00001 /* 00002 * synergy -- mouse and keyboard sharing utility 00003 * Copyright (C) 2012 Bolton Software Ltd. 00004 * Copyright (C) 2002 Chris Schoeneman 00005 * 00006 * This package is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * found in the file COPYING that should have accompanied this file. 00009 * 00010 * This package is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #ifndef CTCPSOCKET_H 00020 #define CTCPSOCKET_H 00021 00022 #include "IDataSocket.h" 00023 #include "CStreamBuffer.h" 00024 #include "CCondVar.h" 00025 #include "CMutex.h" 00026 #include "IArchNetwork.h" 00027 00028 class CMutex; 00029 class CThread; 00030 class ISocketMultiplexerJob; 00031 00033 00036 class CTCPSocket : public IDataSocket { 00037 public: 00038 CTCPSocket(); 00039 CTCPSocket(CArchSocket); 00040 ~CTCPSocket(); 00041 00042 // ISocket overrides 00043 virtual void bind(const CNetworkAddress&); 00044 virtual void close(); 00045 virtual void* getEventTarget() const; 00046 00047 // IStream overrides 00048 virtual UInt32 read(void* buffer, UInt32 n); 00049 virtual void write(const void* buffer, UInt32 n); 00050 virtual void flush(); 00051 virtual void shutdownInput(); 00052 virtual void shutdownOutput(); 00053 virtual bool isReady() const; 00054 virtual UInt32 getSize() const; 00055 00056 // IDataSocket overrides 00057 virtual void connect(const CNetworkAddress&); 00058 00059 private: 00060 void init(); 00061 00062 void setJob(ISocketMultiplexerJob*); 00063 ISocketMultiplexerJob* newJob(); 00064 void sendConnectionFailedEvent(const char*); 00065 void sendEvent(CEvent::Type); 00066 00067 void onConnected(); 00068 void onInputShutdown(); 00069 void onOutputShutdown(); 00070 void onDisconnected(); 00071 00072 ISocketMultiplexerJob* 00073 serviceConnecting(ISocketMultiplexerJob*, 00074 bool, bool, bool); 00075 ISocketMultiplexerJob* 00076 serviceConnected(ISocketMultiplexerJob*, 00077 bool, bool, bool); 00078 00079 private: 00080 CMutex m_mutex; 00081 CArchSocket m_socket; 00082 CStreamBuffer m_inputBuffer; 00083 CStreamBuffer m_outputBuffer; 00084 CCondVar<bool> m_flushed; 00085 bool m_connected; 00086 bool m_readable; 00087 bool m_writable; 00088 }; 00089 00090 #endif
1.7.1