My Project
NPLConnectionManager.h
1 #pragma once
2 #include "util/mutex.h"
3 #include <set>
4 #include <boost/noncopyable.hpp>
5 #include "NPLConnection.h"
6 
7 namespace NPL
8 {
13  class CNPLConnectionManager : private boost::noncopyable
14  {
15  public:
18 
20  void start(NPLConnection_ptr c);
21 
22  /* Add the specified connection to the manager without starting it.
23  * the connection might have been started already or it will is connecting and starting by itself.
24  */
25  void add(NPLConnection_ptr c);
26 
31  void stop(NPLConnection_ptr c, int nReason = 0);
32 
34  void stop_all();
35 
38 
41  {
42  virtual int DoCallBack(const NPLConnection_ptr& c) {return 0;};
43  };
44 
50 
55  int CheckIdleTimeout();
56  private:
57  typedef std::set<NPLConnection_ptr, NPLConnection_PtrOps> NPLConnectionPool_Type;
58 
60  NPLConnectionPool_Type m_connections;
61 
62  ParaEngine::mutex m_mutex;
63  };
64 }
used for various callback.
Definition: NPLConnectionManager.h:40
define this to enable debugging of NPL code in visual studio
Definition: INPL.h:9
void stop(NPLConnection_ptr c, int nReason=0)
Stop the specified connection.
Definition: NPLConnectionManager.cpp:34
int CheckIdleTimeout()
for all active connections, check if any of them should be timed out.
Definition: NPLConnectionManager.cpp:70
void stop_all()
Stop all connections.
Definition: NPLConnectionManager.cpp:43
int get_connection_count()
get the total number of connected connections.
Definition: NPLConnectionManager.cpp:128
cross platform mutex
Definition: mutex.h:95
All incoming and outgoing connection sessions.
Definition: NPLConnectionManager.h:13
int ForEachConnection(NPLConnectionCallBack *pCallback)
it will iterate over all functions, and call NPLConnectionCallBack->DoCallBack(). ...
Definition: NPLConnectionManager.cpp:107
void start(NPLConnection_ptr c)
Add the specified connection to the manager and start it.
Definition: NPLConnectionManager.cpp:25