gloox  0.9.9.12
connectiontcpbase.h
1 /*
2  Copyright (c) 2004-2008 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef CONNECTIONTCPBASE_H__
15 #define CONNECTIONTCPBASE_H__
16 
17 #include "gloox.h"
18 #include "connectionbase.h"
19 #include "logsink.h"
20 #include "mutex.h"
21 
22 #include <string>
23 
24 namespace gloox
25 {
26 
27  class Mutex;
28 
37  class GLOOX_API ConnectionTCPBase : public ConnectionBase
38  {
39  public:
50  ConnectionTCPBase( const LogSink& logInstance, const std::string& server, int port = -1 );
51 
60  ConnectionTCPBase( ConnectionDataHandler *cdh, const LogSink& logInstance,
61  const std::string& server, int port = -1 );
62 
66  virtual ~ConnectionTCPBase();
67 
68  // reimplemented from ConnectionBase
69  virtual bool send( const std::string& data );
70 
71  // reimplemented from ConnectionBase
72  virtual ConnectionError receive();
73 
74  // reimplemented from ConnectionBase
75  virtual void disconnect();
76 
77  // reimplemented from ConnectionBase
78  virtual void cleanup();
79 
80  // reimplemented from ConnectionBase
81  virtual void getStatistics( int &totalIn, int &totalOut );
82 
88  int socket() const { return m_socket; }
89 
96  void setSocket( int socket ) { m_cancel = false; m_socket = socket; }
97 
98  protected:
99  ConnectionTCPBase &operator=( const ConnectionTCPBase & );
100  void init( const std::string& server, int port );
101  bool dataAvailable( int timeout = -1 );
102  void cancel();
103 
104  const LogSink& m_logInstance;
105  Mutex m_sendMutex;
106  Mutex m_recvMutex;
107 
108  char *m_buf;
109  int m_socket;
110  int m_totalBytesIn;
111  int m_totalBytesOut;
112  const int m_bufsize;
113  bool m_cancel;
114 
115  };
116 
117 }
118 
119 #endif // CONNECTIONTCPBASE_H__