connectiontcpbase.h

00001 /*
00002   Copyright (c) 2004-2008 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   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       // reimplemented from ConnectionBase
00069       virtual bool send( const std::string& data );
00070 
00071       // reimplemented from ConnectionBase
00072       virtual ConnectionError receive();
00073 
00074       // reimplemented from ConnectionBase
00075       virtual void disconnect();
00076 
00077       // reimplemented from ConnectionBase
00078       virtual void cleanup();
00079 
00080       // reimplemented from ConnectionBase
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__

Generated on Mon Dec 7 13:28:18 2009 for gloox by  doxygen 1.6.1