My Project
|
All incoming and outgoing connection sessions. More...
#include <NPLConnectionManager.h>
Classes | |
struct | NPLConnectionCallBack |
used for various callback. More... | |
Public Member Functions | |
void | start (NPLConnection_ptr c) |
Add the specified connection to the manager and start it. | |
void | add (NPLConnection_ptr c) |
void | stop (NPLConnection_ptr c, int nReason=0) |
Stop the specified connection. More... | |
void | stop_all () |
Stop all connections. More... | |
int | get_connection_count () |
get the total number of connected connections. More... | |
int | ForEachConnection (NPLConnectionCallBack *pCallback) |
it will iterate over all functions, and call NPLConnectionCallBack->DoCallBack(). More... | |
int | CheckIdleTimeout () |
for all active connections, check if any of them should be timed out. More... | |
All incoming and outgoing connection sessions.
all functions are thread-safe.
int NPL::CNPLConnectionManager::CheckIdleTimeout | ( | ) |
for all active connections, check if any of them should be timed out.
If so, close it or send keep alive message. This function is called by the NPLNetServer from an io service timer that periodically does the checking.
int NPL::CNPLConnectionManager::ForEachConnection | ( | NPLConnectionCallBack * | pCallback | ) |
it will iterate over all functions, and call NPLConnectionCallBack->DoCallBack().
that function should return 0 to continue or 1 to break.
int NPL::CNPLConnectionManager::get_connection_count | ( | ) |
get the total number of connected connections.
void NPL::CNPLConnectionManager::stop | ( | NPLConnection_ptr | c, |
int | nReason = 0 |
||
) |
Stop the specified connection.
nReason | 0 is normal disconnect. 1 is another user with same nid is authenticated. The server should send a message to tell the client about this. |
void NPL::CNPLConnectionManager::stop_all | ( | ) |
Stop all connections.
the following code locks less time. NPLConnection_ptr conn; NPLConnectionPool_Type::iterator iter; while(true) { { ParaEngine::Lock lock_(m_mutex); NPLConnectionPool_Type::iterator iter = m_connections.begin(); if(iter!=m_connections.end()) { conn = *iter; m_connections.erase(iter); } else break; } conn->stop(false); }