My Project
NPL_TCPConnection.h
1 #pragma once
2 
3 #include "ParaRingBuffer.h"
4 
5 #include <boost/bind.hpp>
6 #include <boost/asio.hpp>
7 #include <boost/thread.hpp>
8 
9 // this is the gloox client
10 #include <gloox.h>
11 #include <connectionbase.h>
12 #include <logsink.h>
13 
14 namespace ParaEngine
15 {
16  using namespace gloox;
17  using boost::asio::ip::tcp;
18 
25  class CNPLTCPConnection : public ConnectionBase
26  {
27  public:
29 
40  CNPLTCPConnection( boost::asio::io_service& io_service, const LogSink& logInstance, const std::string& server, int port = -1 );
41 
50  CNPLTCPConnection( boost::asio::io_service& io_service, ConnectionDataHandler *cdh, const LogSink& logInstance,
51  const std::string& server, int port = -1 );
52 
56  virtual ~CNPLTCPConnection();
57 
58  // reimplemented from ConnectionBase
59  virtual bool send( const std::string& data );
60 
61  // reimplemented from ConnectionBase
62  virtual ConnectionError receive();
63 
64  // reimplemented from ConnectionBase
65  virtual void disconnect();
66 
67  // reimplemented from ConnectionBase
68  virtual void cleanup();
69 
70  // reimplemented from ConnectionBase
71  virtual void getStatistics( long int &totalIn, long int &totalOut );
72 
73 
74  // reimplemented from ConnectionBase
75  virtual ConnectionError recv( int timeout = -1 );
76 
77  // reimplemented from ConnectionBase
78  virtual ConnectionError connect();
79 
80  // reimplemented from ConnectionBase
81  virtual ConnectionBase* newInstance() const;
82 
84  void NotifyDisconnect(ConnectionError error);
85 
87  bool HasNotification();
88 
91  int HandleNotification();
92 
94  void Reset( const std::string& server, int port );
95  protected:
97  // IO event handlers
99 
100  void handle_resolve(const boost::system::error_code& err, tcp::resolver::iterator endpoint_iterator);
101  void handle_connect(const boost::system::error_code& error, tcp::resolver::iterator endpoint_iterator);
102  void handle_read(const boost::system::error_code& error, std::size_t bytes_transferred);
103  void handle_write(const boost::system::error_code& error);
104  void handle_disconnect();
105 
106  protected:
107  CNPLTCPConnection &operator=( const CNPLTCPConnection & );
108  void init( const std::string& server, int port );
109 
110  const LogSink& m_logInstance;
111 
112  // the receive buffer
113  char *m_buf;
114  const int m_bufsize;
115  long int m_totalBytesIn;
116  long int m_totalBytesOut;
117  std::string m_strPort;
118 
119  tcp::socket m_socket;
120  tcp::resolver m_resolver;
122  boost::asio::io_service * m_pIOService;
123 
127  ConnectionError m_nDisconnectError;
128 
129  ParaEngine::mutex m_mutex;
130 
132  RingBuffer_Type m_queueOutput;
133 
135  RingBuffer_Type m_queueInput;
136 
137  };
138 }
different physics engine has different winding order.
Definition: EventBinding.h:32
boost::asio::io_service * m_pIOService
dispatcher IO service object for the connection socket.
Definition: NPL_TCPConnection.h:122
RingBuffer_Type m_queueInput
the input message queue.
Definition: NPL_TCPConnection.h:135
boost::asio is used for NPL jabber client&#39;s tcp connections.
Definition: NPL_TCPConnection.h:25
RingBuffer_Type m_queueOutput
the output message queue.
Definition: NPL_TCPConnection.h:132
ConnectionError m_nDisconnectError
disconnection error message.
Definition: NPL_TCPConnection.h:127
Definition: error.hpp:46
bool m_bNotifyDisconnect
true to notify disconnection
Definition: NPL_TCPConnection.h:125
cross platform mutex
Definition: mutex.h:95