Layer 4. More...
#include <net_manager.h>
Static Public Member Functions | |
| static void | init (const CInetAddress *addr, CCallbackNetBase::TRecordingState rec) |
| Creates the connection to the Naming Service. | |
| static void | release () |
| static void | addServer (const std::string &serviceName, uint16 servicePort=0, bool external=false) |
| Sets up a server on a specific port with a specific service name (create a listen socket, register to naming service and so on) If servicePort is 0, it will be dynamically determinated by the Naming Service. | |
| static void | addServer (const std::string &serviceName, uint16 servicePort, NLNET::TServiceId &sid, bool external=false) |
| static void | addClient (const std::string &serviceName, const std::string &addr, bool autoRetry=true) |
| Creates a connection to a specific IP and associate it this a "fake" serviceName (to enable you to send data for example). | |
| static void | addClient (const std::string &serviceName) |
| Creates a connection to a service using the naming service and the serviceName. | |
| static void | addGroup (const std::string &groupName, const std::string &serviceName) |
| Creates connections to a group of service. | |
| static void | addCallbackArray (const std::string &serviceName, const TCallbackItem *callbackarray, NLMISC::CStringIdArray::TStringId arraysize) |
| Adds a callback array to a specific service connection. You can add callback only *after* adding the server, the client or the group. | |
| static void | update (NLMISC::TTime timeout=0) |
| Call it evenly. | |
| static void | send (const std::string &serviceName, const CMessage &buffer, TSockId hostid=InvalidSockId) |
| Sends a message to a specific serviceName. | |
| static void | setConnectionCallback (const std::string &serviceName, TNetManagerCallback cb, void *arg) |
| Sets callback for incoming connections (or NULL to disable callback) On a client, the callback will be call when the connection to the server is established (the first connection or after the server shutdown and started) On a server, the callback is called each time a new client is connected to him. | |
| static void | setDisconnectionCallback (const std::string &serviceName, TNetManagerCallback cb, void *arg) |
| Sets callback for disconnections (or NULL to disable callback) On a client, the callback will be call each time the connection to the server is lost On a server, the callback is called each time a client is disconnected. | |
| static CCallbackNetBase * | getNetBase (const std::string &serviceName) |
| Returns the connection if you want to do specific calls. | |
| static void | setUpdateTimeout (uint32 timeout) |
| static void | createConnection (CBaseStruct &Base, const CInetAddress &Addr, const std::string &name) |
| static uint64 | getBytesSent () |
| static uint64 | getBytesReceived () |
| static uint64 | getReceiveQueueSize () |
| static uint64 | getSendQueueSize () |
Private Types | |
| typedef std::map< std::string, CBaseStruct > | TBaseMap |
| typedef TBaseMap::iterator | ItBaseMap |
Private Member Functions | |
| CNetManager () | |
Static Private Member Functions | |
| static ItBaseMap | find (const std::string &serviceName) |
Static Private Attributes | |
| static TBaseMap | _BaseMap |
| static CCallbackNetBase::TRecordingState | _RecordingState |
| static NLMISC::TTime | _NextUpdateTime = 0 |
Friends | |
| void | RegistrationBroadcast (const std::string &name, TServiceId sid, const std::vector< CInetAddress > &addr) |
Layer 4.
In case of addGroup(), messages are *not* associate with id, so the message type is always sent with string.
Definition at line 102 of file net_manager.h.
typedef TBaseMap::iterator NLNET::CNetManager::ItBaseMap [private] |
Definition at line 171 of file net_manager.h.
typedef std::map<std::string, CBaseStruct> NLNET::CNetManager::TBaseMap [private] |
Definition at line 170 of file net_manager.h.
| NLNET::CNetManager::CNetManager | ( | ) | [inline, private] |
Definition at line 188 of file net_manager.h.
| static void NLNET::CNetManager::addCallbackArray | ( | const std::string & | serviceName, | |
| const TCallbackItem * | callbackarray, | |||
| NLMISC::CStringIdArray::TStringId | arraysize | |||
| ) | [static] |
Adds a callback array to a specific service connection. You can add callback only *after* adding the server, the client or the group.
| void NLNET::CNetManager::addClient | ( | const std::string & | serviceName | ) | [static] |
Creates a connection to a service using the naming service and the serviceName.
Definition at line 264 of file net_manager.cpp.
References _RecordingState, NLNET::CBaseStruct::Client, NLNET::CNamingClient::connected(), find(), NLNET::CNamingClient::lookupAndConnect(), nlassert, nldebug, and NLNET::nmNewDisconnection().
| void NLNET::CNetManager::addClient | ( | const std::string & | serviceName, | |
| const std::string & | addr, | |||
| bool | autoRetry = true | |||
| ) | [static] |
Creates a connection to a specific IP and associate it this a "fake" serviceName (to enable you to send data for example).
Definition at line 240 of file net_manager.cpp.
References NLNET::CBaseStruct::ClientWithAddr, createConnection(), find(), nlassert, and nldebug.
| void NLNET::CNetManager::addGroup | ( | const std::string & | groupName, | |
| const std::string & | serviceName | |||
| ) | [static] |
Creates connections to a group of service.
Definition at line 291 of file net_manager.cpp.
References NLNET::CNamingClient::connected(), createConnection(), find(), NLNET::CBaseStruct::Group, NLNET::CNamingClient::lookupAll(), nlassert, and nldebug.
| void NLNET::CNetManager::addServer | ( | const std::string & | serviceName, | |
| uint16 | servicePort, | |||
| NLNET::TServiceId & | sid, | |||
| bool | external = false | |||
| ) | [static] |
Definition at line 191 of file net_manager.cpp.
References _RecordingState, NLNET::CNamingClient::connected(), find(), NLNET::TServiceId::get(), NLNET::CInetAddress::localAddresses(), nlassert, nldebug, nlinfo, NLNET::nmNewConnection(), NLNET::nmNewDisconnection(), NLNET::CNamingClient::queryServicePort(), NLNET::CNamingClient::registerService(), NLNET::CNamingClient::registerServiceWithSId(), and NLNET::CBaseStruct::Server.
| void NLNET::CNetManager::addServer | ( | const std::string & | serviceName, | |
| uint16 | servicePort = 0, |
|||
| bool | external = false | |||
| ) | [static] |
Sets up a server on a specific port with a specific service name (create a listen socket, register to naming service and so on) If servicePort is 0, it will be dynamically determinated by the Naming Service.
If sid id 0, the service id will be dynamically determinated by the Naming Service.
Definition at line 185 of file net_manager.cpp.
| void NLNET::CNetManager::createConnection | ( | CBaseStruct & | Base, | |
| const CInetAddress & | Addr, | |||
| const std::string & | name | |||
| ) | [static] |
Definition at line 81 of file net_manager.cpp.
References _RecordingState, NLNET::CCallbackClient::connect(), NLNET::CCallbackClient::getSockId(), NLNET::CBaseStruct::NetBase, nlinfo, NLNET::nmNewDisconnection(), and NLMISC::Exception::what().
Referenced by addClient(), addGroup(), and NLNET::RegistrationBroadcast().
| CNetManager::ItBaseMap NLNET::CNetManager::find | ( | const std::string & | serviceName | ) | [static, private] |
Definition at line 460 of file net_manager.cpp.
References _BaseMap.
Referenced by addClient(), addGroup(), addServer(), getNetBase(), send(), setConnectionCallback(), and setDisconnectionCallback().
| uint64 NLNET::CNetManager::getBytesReceived | ( | ) | [static] |
Definition at line 481 of file net_manager.cpp.
References _BaseMap.
| uint64 NLNET::CNetManager::getBytesSent | ( | ) | [static] |
Definition at line 468 of file net_manager.cpp.
References _BaseMap.
| CCallbackNetBase * NLNET::CNetManager::getNetBase | ( | const std::string & | serviceName | ) | [static] |
Returns the connection if you want to do specific calls.
Definition at line 437 of file net_manager.cpp.
References find().
| uint64 NLNET::CNetManager::getReceiveQueueSize | ( | ) | [static] |
Definition at line 507 of file net_manager.cpp.
References _BaseMap.
| uint64 NLNET::CNetManager::getSendQueueSize | ( | ) | [static] |
Definition at line 494 of file net_manager.cpp.
References _BaseMap.
| void NLNET::CNetManager::init | ( | const CInetAddress * | addr, | |
| CCallbackNetBase::TRecordingState | rec | |||
| ) | [static] |
Creates the connection to the Naming Service.
If the connection failed, ESocketConnectionFailed exception is generated.
Definition at line 153 of file net_manager.cpp.
References _RecordingState, NLNET::CNamingClient::connect(), NLNET::CInetAddress::localAddresses(), RegistrationBroadcast, NLNET::CNamingClient::setRegistrationBroadcastCallback(), NLNET::CNamingClient::setUnregistrationBroadcastCallback(), and NLNET::UnregistrationBroadcast().
| void NLNET::CNetManager::release | ( | void | ) | [static] |
Definition at line 169 of file net_manager.cpp.
References _BaseMap, NLNET::CNamingClient::connected(), and NLNET::CNamingClient::disconnect().
| void NLNET::CNetManager::send | ( | const std::string & | serviceName, | |
| const CMessage & | buffer, | |||
| TSockId | hostid = InvalidSockId | |||
| ) | [static] |
Sends a message to a specific serviceName.
Definition at line 426 of file net_manager.cpp.
References NLNET::CBufSock::asString(), find(), nldebug, and NLNET::CMessage::toString().
| void NLNET::CNetManager::setConnectionCallback | ( | const std::string & | serviceName, | |
| TNetManagerCallback | cb, | |||
| void * | arg | |||
| ) | [static] |
Sets callback for incoming connections (or NULL to disable callback) On a client, the callback will be call when the connection to the server is established (the first connection or after the server shutdown and started) On a server, the callback is called each time a new client is connected to him.
Definition at line 443 of file net_manager.cpp.
| void NLNET::CNetManager::setDisconnectionCallback | ( | const std::string & | serviceName, | |
| TNetManagerCallback | cb, | |||
| void * | arg | |||
| ) | [static] |
Sets callback for disconnections (or NULL to disable callback) On a client, the callback will be call each time the connection to the server is lost On a server, the callback is called each time a client is disconnected.
Definition at line 451 of file net_manager.cpp.
| static void NLNET::CNetManager::setUpdateTimeout | ( | uint32 | timeout | ) | [static] |
| static void NLNET::CNetManager::update | ( | NLMISC::TTime | timeout = 0 |
) | [static] |
Call it evenly.
the parameter select the timeout value in milliseconds for each update. You are absolutely certain that this function will not be returns before this amount of time you set. If you set the update timeout value higher than 0, all messages in queues will be process until the time is greater than the timeout user update(). If you set the update timeout value to 0, all messages in queues will be process one time before calling the user update(). In this case, we don't nlSleep(1).
| void RegistrationBroadcast | ( | const std::string & | name, | |
| TServiceId | sid, | |||
| const std::vector< CInetAddress > & | addr | |||
| ) | [friend] |
Definition at line 115 of file net_manager.cpp.
Referenced by init().
CNetManager::TBaseMap NLNET::CNetManager::_BaseMap [static, private] |
Definition at line 174 of file net_manager.h.
Referenced by find(), getBytesReceived(), getBytesSent(), getReceiveQueueSize(), getSendQueueSize(), NLNET::RegistrationBroadcast(), and release().
TTime NLNET::CNetManager::_NextUpdateTime = 0 [static, private] |
Definition at line 179 of file net_manager.h.
CCallbackNetBase::TRecordingState NLNET::CNetManager::_RecordingState [static, private] |
Definition at line 176 of file net_manager.h.
Referenced by addClient(), addServer(), createConnection(), and init().
1.6.1