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 class Mutex;
00028
00037 class GLOOX_API ConnectionTCPBase : public ConnectionBase
00038 {
00039 public:
00050 ConnectionTCPBase( const LogSink& logInstance, const std::string& server, int port = -1 );
00051
00060 ConnectionTCPBase( ConnectionDataHandler *cdh, const LogSink& logInstance,
00061 const std::string& server, int port = -1 );
00062
00066 virtual ~ConnectionTCPBase();
00067
00068
00069 virtual bool send( const std::string& data );
00070
00071
00072 virtual ConnectionError receive();
00073
00074
00075 virtual void disconnect();
00076
00077
00078 virtual void cleanup();
00079
00080
00081 virtual void getStatistics( int &totalIn, int &totalOut );
00082
00088 int socket() const { return m_socket; }
00089
00096 void setSocket( int socket ) { m_cancel = false; m_socket = socket; }
00097
00098 protected:
00099 ConnectionTCPBase &operator=( const ConnectionTCPBase & );
00100 void init( const std::string& server, int port );
00101 bool dataAvailable( int timeout = -1 );
00102 void cancel();
00103
00104 const LogSink& m_logInstance;
00105 Mutex m_sendMutex;
00106 Mutex m_recvMutex;
00107
00108 char *m_buf;
00109 int m_socket;
00110 int m_totalBytesIn;
00111 int m_totalBytesOut;
00112 const int m_bufsize;
00113 bool m_cancel;
00114
00115 };
00116
00117 }
00118
00119 #endif // CONNECTIONTCPBASE_H__