connectiontcpbase.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef CONNECTIONTCPBASE_H__
00015 #define CONNECTIONTCPBASE_H__
00016
00017 #include "gloox.h"
00018 #include "connectionbase.h"
00019 #include "logsink.h"
00020 #include "mutex.h"
00021
00022 #include <string>
00023
00024 namespace gloox
00025 {
00026
00027 namespace util
00028 {
00029 class Mutex;
00030 }
00031
00040 class GLOOX_API ConnectionTCPBase : public ConnectionBase
00041 {
00042 public:
00053 ConnectionTCPBase( const LogSink& logInstance, const std::string& server, int port = -1 );
00054
00063 ConnectionTCPBase( ConnectionDataHandler* cdh, const LogSink& logInstance,
00064 const std::string& server, int port = -1 );
00065
00069 virtual ~ConnectionTCPBase();
00070
00071
00072 virtual bool send( const std::string& data );
00073
00074
00075 virtual ConnectionError receive();
00076
00077
00078 virtual void disconnect();
00079
00080
00081 virtual void cleanup();
00082
00083
00084 virtual void getStatistics( long int &totalIn, long int &totalOut );
00085
00091 int socket() const { return m_socket; }
00092
00099 void setSocket( int socket ) { m_cancel = false; m_state = StateConnected; m_socket = socket; }
00100
00105 virtual int localPort() const;
00106
00111 virtual const std::string localInterface() const;
00112
00113 protected:
00114 ConnectionTCPBase& operator=( const ConnectionTCPBase& );
00115 void init( const std::string& server, int port );
00116 bool dataAvailable( int timeout = -1 );
00117 void cancel();
00118
00119 const LogSink& m_logInstance;
00120 util::Mutex m_sendMutex;
00121 util::Mutex m_recvMutex;
00122
00123 char* m_buf;
00124 int m_socket;
00125 long int m_totalBytesIn;
00126 long int m_totalBytesOut;
00127 const int m_bufsize;
00128 bool m_cancel;
00129
00130 };
00131
00132 }
00133
00134 #endif // CONNECTIONTCPBASE_H__