gloox 1.0
|
00001 /* 00002 Copyright (c) 2004-2009 by Jakob Schroeter <js@camaya.net> 00003 This file is part of the gloox library. http://camaya.net/gloox 00004 00005 This software is distributed under a license. The full license 00006 agreement can be found in the file LICENSE in this distribution. 00007 This software may not be copied, modified, sold or distributed 00008 other than expressed in the named license agreement. 00009 00010 This software is distributed without any warranty. 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 // reimplemented from ConnectionBase 00072 virtual bool send( const std::string& data ); 00073 00074 // reimplemented from ConnectionBase 00075 virtual ConnectionError receive(); 00076 00077 // reimplemented from ConnectionBase 00078 virtual void disconnect(); 00079 00080 // reimplemented from ConnectionBase 00081 virtual void cleanup(); 00082 00083 // reimplemented from ConnectionBase 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__