My Project
Classes | Public Member Functions | List of all members
NPL::CNPLConnectionManager Class Reference

All incoming and outgoing connection sessions. More...

#include <NPLConnectionManager.h>

Inheritance diagram for NPL::CNPLConnectionManager:

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...
 

Detailed Description

All incoming and outgoing connection sessions.

all functions are thread-safe.

Member Function Documentation

§ CheckIdleTimeout()

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.

Returns
the number of timed out connections.

§ ForEachConnection()

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.

Returns
the total number of connections

§ get_connection_count()

int NPL::CNPLConnectionManager::get_connection_count ( )

get the total number of connected connections.

§ stop()

void NPL::CNPLConnectionManager::stop ( NPLConnection_ptr  c,
int  nReason = 0 
)

Stop the specified connection.

Parameters
nReason0 is normal disconnect. 1 is another user with same nid is authenticated. The server should send a message to tell the client about this.

§ stop_all()

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); }


The documentation for this class was generated from the following files: