NLNET::CUnifiedNetwork Class Reference

Layer 5. More...

#include <unified_network.h>

Inherits NLMISC::ICommandsHandler.

List of all members.

Classes

class  CUnifiedConnection
 This may contains a CCallbackClient or a TSockId, depending on which type of connection it is. More...
struct  TNameMappedConnection
 A map of service ids, referred by a service name. More...

Public Member Functions

virtual const std::string & getCommandHandlerName () const
 This methods implemented by CCommandHandler is used by the command registry to retrieve the name of the object instance.
bool init (const CInetAddress *addr, CCallbackNetBase::TRecordingState rec, const std::string &shortName, uint16 port, TServiceId &sid)
 Creates the connection to the Naming Service.
void connect ()
 Registers to the Naming Service, and connects to the present services.
void release (bool mustFlushSendQueues=true, const std::vector< std::string > &namesOfOnlyServiceToFlushSending=std::vector< std::string >())
 Closes the connection to the naming service, every other connection and free.
void addService (const std::string &name, const CInetAddress &addr, bool sendId=true, bool external=true, TServiceId sid=TServiceId(), bool autoRetry=true, bool shouldBeAlreayInserted=false)
 Adds a specific service to the list of connected services.
void addService (const std::string &name, const std::vector< CInetAddress > &addr, bool sendId=true, bool external=true, TServiceId sid=TServiceId(), bool autoRetry=true, bool shouldBeAlreayInserted=false)
void addCallbackArray (const TUnifiedCallbackItem *callbackarray, sint arraysize)
 Adds a callback array in the system.
void update (NLMISC::TTime timeout=0)
 Call it evenly.
uint send (const std::string &serviceName, const CMessage &msg, bool warnIfNotFound=true, uint8 nid=0xFF)
 Sends a message to a specific serviceName.
bool send (TServiceId serviceId, const CMessage &msg, uint8 nid=0xFF)
 Sends a message to a specific serviceId.
void sendAll (const CMessage &msg, uint8 nid=0xFF)
 Broadcasts a message to all connected services.
uint tryFlushAllQueues (const std::vector< std::string > &namesOfOnlyServiceToFlushSending=std::vector< std::string >())
 Flush all or part of the sending queues, and report the number of bytes still pending.
void setServiceUpCallback (const std::string &serviceName, TUnifiedNetCallback cb, void *arg=0, bool back=true)
 Sets callback for incoming connections.
void removeServiceUpCallback (const std::string &serviceName, TUnifiedNetCallback cb, void *arg=0)
 Remove a service up callback.
void setServiceDownCallback (const std::string &serviceName, TUnifiedNetCallback cb, void *arg=0, bool back=true)
 Sets callback for disconnections.
void removeServiceDownCallback (const std::string &serviceName, TUnifiedNetCallback cb, void *arg=0)
 Remove a service down callback.
void addNetworkAssociation (const std::string &networkName, uint8 nid)
 Associate a string with a network id If the send don't set a specific nid, it ll use the 0, so be sure that the nid 0 is set to a network.
void clearNetworkAssociation ()
 Clear all network association.
void addDefaultNetwork (const std::string &defnet)
 This array says to which network we need to send the message for the default nid.
void clearDefaultNetwork ()
 Clear all default network.
bool isServiceLocal (TServiceId sid)
 Returns true if the sid service is on the same computer than this service.
bool isServiceLocal (const std::string &serviceName)
 Returns true if the serviceName service is on the same computer than this service.
std::string getServiceName (TServiceId sid)
 Return the name of the specified service, or "" if not found.
std::string getServiceUnifiedName (TServiceId sid)
 Return a string identifying the service, using the format "NAME-sid" (or "sid" only if not found).
CCallbackNetBasegetNetBase (const std::string &name, TSockId &host, uint8 nid=0xFF)
CCallbackNetBasegetNetBase (TServiceId sid, TSockId &host, uint8 nid=0xFF)
 Gets the CCallbackNetBase of the service.
uint64 getBytesSent ()
 Gets the total number of bytes sent.
uint64 getBytesReceived ()
 Gets the total number of bytes received.
uint64 getSendQueueSize ()
 Gets the total number of bytes queued for sending.
uint64 getReceiveQueueSize ()
 Gets the total number of bytes queued after receiving.
TUnifiedMsgCallback findCallback (const std::string &callbackName)
 Find a callback in the array.
const std::vector< TServiceId > & getConnectionList () const
 Return the service ids of the active connections.
bool isConnectionConnected (TServiceId sid) const
 Return the state of the connection (return true if the connection is fully connected).
void displayInternalTables (NLMISC::CLog *log=NLMISC::InfoLog)
void displayUnifiedConnection (TServiceId sid, NLMISC::CLog *log=NLMISC::InfoLog)

Static Public Member Functions

static bool isUsed ()
 Returns the singleton instance of the CUnifiedNetwork class.

Protected Member Functions

void autoReconnect (CUnifiedConnection &uc, uint connectionIndex)
 Auto-reconnect.
void sleepUntilDataAvailable (NLMISC::TTime msecMax)
 Sleep (implemented by select()).

Private Types

typedef std::map< std::string,
TUnifiedMsgCallback
TMsgMappedCallback
 A map of callbacks, referred by message name.
typedef std::pair
< TUnifiedNetCallback, void * > 
TCallbackArgItem
 A callback and its user data.
typedef CHashMap< std::string,
std::list< TCallbackArgItem > > 
TNameMappedCallback
 A map of service up/down callbacks with their user data.

Private Member Functions

 NLMISC_SAFE_SINGLETON_DECL_PTR (CUnifiedNetwork)
NLMISC_COMMAND_HANDLER_TABLE_END NLMISC_CLASS_COMMAND_DECL (addService)
 CUnifiedNetwork ()
 ~CUnifiedNetwork ()
void autoCheck ()
CUnifiedConnectiongetUnifiedConnection (TServiceId sid, bool warn=true)
bool haveNamedCnx (const std::string &name, TServiceId sid)
void addNamedCnx (const std::string &name, TServiceId sid)
void removeNamedCnx (const std::string &name, TServiceId sid)
uint8 findConnectionId (TServiceId sid, uint8 nid)
void callServiceUpCallback (const std::string &serviceName, TServiceId sid, bool callGlobalCallback=true)
void callServiceDownCallback (const std::string &serviceName, TServiceId sid, bool callGlobalCallback=true)

Private Attributes

std::vector< CUnifiedConnection_IdCnx
 Vector of connections by service id (sid is the entry in this array, it means that there s some hole).
std::vector< TServiceId_ConnectionToReset
 Vector of closed connection to reset outside of the client update loop.
std::vector< TServiceId_UsedConnection
 This vector contains only an index to the unified connection. It is used to have quick access on the available connections.
TNameMappedConnection _NamedCnx
 Map of connections by service name.
CCallbackServer_CbServer
 The callback server.
TNameMappedCallback _UpCallbacks
 Map of the up/down service callbacks.
std::vector< TCallbackArgItem_UpUniCallback
TNameMappedCallback _DownCallbacks
std::vector< TCallbackArgItem_DownUniCallback
CCallbackNetBase::TRecordingState _RecordingState
 Recording state.
std::string _Name
 Service name.
TMsgMappedCallback _Callbacks
 Map of callbacks.
uint16 _ServerPort
 The server port.
TServiceId _ExtSId
 Used for external service.
NLMISC::TTime _LastRetry
 Last time of retry.
NLMISC::TTime _NextUpdateTime
 Time of the theoretical next update.
NLNET::CInetAddress _NamingServiceAddr
 The main instance.
std::vector< uint32_NetworkAssociations
 for each nid, which network address
std::vector< std::string > _DefaultNetwork
 for each services, which network to take
int _MainDataAvailablePipe [2]
 Pipe to select() on data available (shared among all connections).
TServiceId _SId
 Service id of the running service.
bool _Initialised
 true if initialization function called

Friends

struct nel_isServiceLocalClass
struct nel_l5CallbackClass
struct nel_l5QueuesStatsClass
void uncbConnection (TSockId from, void *arg)
void uncbDisconnection (TSockId from, void *arg)
void uncbServiceIdentification (CMessage &msgin, TSockId from, CCallbackNetBase &netbase)
void uncbMsgProcessing (CMessage &msgin, TSockId from, CCallbackNetBase &netbase)
void uNetRegistrationBroadcast (const std::string &name, TServiceId sid, const std::vector< CInetAddress > &addr)
void uNetUnregistrationBroadcast (const std::string &name, TServiceId sid, const std::vector< CInetAddress > &addr)

Detailed Description

Layer 5.

When calling send(), a message is stored in a queue. It will be effectively sent when a flush is done. By default, the variable FlushSendsBeforeSleep is on so that the message is sent in the same update cycle as the send() call. If FlushSendsBeforeSleep is set to off, more messages will be sent together, but with a greater delay.

Handling network congestion: When a destination service is not fast enough to process the incoming messages, the uploading stream can get saturated. As a result, a single flush will not manage to send the entire data at a time. The NeL Network Layer 5 will silently continue streaming up the remaining parts of the unsent data, as long as update() is called evenly. More in depth:

Author:
Vianney Lecroart, Benjamin Legros, Olivier Cado
Nevrax France
Date:
2002-2004

Definition at line 233 of file unified_network.h.


Member Typedef Documentation

typedef std::pair<TUnifiedNetCallback, void *> NLNET::CUnifiedNetwork::TCallbackArgItem [private]

A callback and its user data.

Definition at line 452 of file unified_network.h.

typedef std::map<std::string, TUnifiedMsgCallback> NLNET::CUnifiedNetwork::TMsgMappedCallback [private]

A map of callbacks, referred by message name.

Definition at line 449 of file unified_network.h.

typedef CHashMap<std::string, std::list<TCallbackArgItem> > NLNET::CUnifiedNetwork::TNameMappedCallback [private]

A map of service up/down callbacks with their user data.

Definition at line 455 of file unified_network.h.


Constructor & Destructor Documentation

NLNET::CUnifiedNetwork::CUnifiedNetwork (  )  [inline, private]

Definition at line 718 of file unified_network.h.

NLNET::CUnifiedNetwork::~CUnifiedNetwork (  )  [inline, private]

Definition at line 728 of file unified_network.h.


Member Function Documentation

void NLNET::CUnifiedNetwork::addCallbackArray ( const TUnifiedCallbackItem callbackarray,
sint  arraysize 
)

Adds a callback array in the system.

You can add callback only *after* adding the server, the client or the group.

Definition at line 1461 of file unified_network.cpp.

References _Callbacks.

Referenced by NLNET::CGatewayL5Transport::open().

void NLNET::CUnifiedNetwork::addDefaultNetwork ( const std::string &  defnet  )  [inline]

This array says to which network we need to send the message for the default nid.

For example you can says that message for AES will use the network 0 and message for LS will use the network 1. To do that, just call the function with string "AES0" and "LS1" the number is the nid (look at addNetworkAssociation()) addNetworkAssociation("192.168.0.0", 0); addNetworkAssociation("192.168.1.0", 1); In this case if you send a message to AES with default nid, it'll be send to 192.168.0.x In this case if you send a message to LS with default nid, it'll be send to 192.168.1.y

Definition at line 389 of file unified_network.h.

References _DefaultNetwork, and nlinfo.

void NLNET::CUnifiedNetwork::addNamedCnx ( const std::string &  name,
TServiceId  sid 
) [private]
void NLNET::CUnifiedNetwork::addNetworkAssociation ( const std::string &  networkName,
uint8  nid 
)

Associate a string with a network id If the send don't set a specific nid, it ll use the 0, so be sure that the nid 0 is set to a network.

You must call this function before the connect() function.

Parameters:
networkName must be in a xxx.xxx.xxx.xxx format. The low value will be ignore depending of the network class.
nid a number (used as an index in a vector for constant access so numbers should be contiguous) that will be use to send to this network.

Definition at line 2067 of file unified_network.cpp.

References _NetworkAssociations, NLNET::internalIPAddressToString(), nlinfo, and NLNET::stringToInternalIPAddress().

void NLNET::CUnifiedNetwork::addService ( const std::string &  name,
const std::vector< CInetAddress > &  addr,
bool  sendId = true,
bool  external = true,
TServiceId  sid = TServiceId(),
bool  autoRetry = true,
bool  shouldBeAlreayInserted = false 
)
void NLNET::CUnifiedNetwork::addService ( const std::string &  name,
const CInetAddress addr,
bool  sendId = true,
bool  external = true,
TServiceId  sid = TServiceId(),
bool  autoRetry = true,
bool  shouldBeAlreayInserted = false 
)

Adds a specific service to the list of connected services.

If the connection succeeds immediately (i.e. the specified service is already online), service up callbacks (for this service and for "*") will be called from within addService(). If the service is not available, the connection will be attempted evently in a background thread. Then when it will become available, the service up callbacks will be called.

Warning: currently, this method must not be called within a network callback.

Definition at line 764 of file unified_network.cpp.

Referenced by connect().

void NLNET::CUnifiedNetwork::autoCheck (  )  [private]
void NLNET::CUnifiedNetwork::autoReconnect ( CUnifiedConnection uc,
uint  connectionIndex 
) [protected]
void NLNET::CUnifiedNetwork::callServiceDownCallback ( const std::string &  serviceName,
TServiceId  sid,
bool  callGlobalCallback = true 
) [private]

Definition at line 2105 of file unified_network.cpp.

References _DownCallbacks, _DownUniCallback, NLNET::cb, and nlwarning.

Referenced by NLNET::uncbDisconnection().

void NLNET::CUnifiedNetwork::callServiceUpCallback ( const std::string &  serviceName,
TServiceId  sid,
bool  callGlobalCallback = true 
) [private]
void NLNET::CUnifiedNetwork::clearDefaultNetwork (  )  [inline]

Clear all default network.

Definition at line 392 of file unified_network.h.

References _DefaultNetwork.

void NLNET::CUnifiedNetwork::clearNetworkAssociation (  )  [inline]

Clear all network association.

Definition at line 380 of file unified_network.h.

References _NetworkAssociations.

void NLNET::CUnifiedNetwork::connect (  ) 

Registers to the Naming Service, and connects to the present services.

Definition at line 648 of file unified_network.cpp.

References _Initialised, _SId, addService(), NLNET::CNamingClient::connected(), NLNET::CNamingClient::getRegisteredServices(), NLMISC::getThreadId(), nlassertex, nlwarning, and NLNET::ThreadCreator.

Referenced by init().

void NLNET::CUnifiedNetwork::displayInternalTables ( NLMISC::CLog log = NLMISC::InfoLog  ) 
void NLNET::CUnifiedNetwork::displayUnifiedConnection ( TServiceId  sid,
NLMISC::CLog log = NLMISC::InfoLog 
) [inline]
TUnifiedMsgCallback NLNET::CUnifiedNetwork::findCallback ( const std::string &  callbackName  ) 

Find a callback in the array.

Definition at line 1745 of file unified_network.cpp.

References _Callbacks.

uint8 NLNET::CUnifiedNetwork::findConnectionId ( TServiceId  sid,
uint8  nid 
) [private]

Definition at line 1267 of file unified_network.cpp.

References _IdCnx, NLNET::TServiceId::get(), and nlwarning.

Referenced by getNetBase(), send(), and sendAll().

uint64 NLNET::CUnifiedNetwork::getBytesReceived (  ) 

Gets the total number of bytes received.

Definition at line 1633 of file unified_network.cpp.

References _CbServer, _IdCnx, _UsedConnection, NLNET::CCallbackNetBase::getBytesReceived(), and NLNET::CUnifiedNetwork::CUnifiedConnection::Ready.

uint64 NLNET::CUnifiedNetwork::getBytesSent (  ) 
virtual const std::string& NLNET::CUnifiedNetwork::getCommandHandlerName (  )  const [inline, virtual]

This methods implemented by CCommandHandler is used by the command registry to retrieve the name of the object instance.

Implements NLMISC::ICommandsHandler.

Definition at line 239 of file unified_network.h.

const std::vector<TServiceId>& NLNET::CUnifiedNetwork::getConnectionList (  )  const [inline]

Return the service ids of the active connections.

Definition at line 431 of file unified_network.h.

References _UsedConnection.

Referenced by NLNET::CGatewayL5Transport::open().

CCallbackNetBase * NLNET::CUnifiedNetwork::getNetBase ( TServiceId  sid,
TSockId host,
uint8  nid = 0xFF 
)
CCallbackNetBase * NLNET::CUnifiedNetwork::getNetBase ( const std::string &  name,
TSockId host,
uint8  nid = 0xFF 
)
Warning:
You should not use getNetBase functions because it could have more than one connection to a service and in this case it ll return the first connection Gets the CCallbackNetBase of the service

Definition at line 1687 of file unified_network.cpp.

References _IdCnx, _Initialised, _NamedCnx, findConnectionId(), NLMISC::getThreadId(), NLNET::InvalidSockId, nlassertex, nlwarning, and NLNET::ThreadCreator.

uint64 NLNET::CUnifiedNetwork::getReceiveQueueSize (  ) 

Gets the total number of bytes queued after receiving.

Definition at line 1669 of file unified_network.cpp.

References _CbServer, _IdCnx, _UsedConnection, NLNET::CCallbackServer::getReceiveQueueSize(), and NLNET::CUnifiedNetwork::CUnifiedConnection::Ready.

uint64 NLNET::CUnifiedNetwork::getSendQueueSize (  ) 

Gets the total number of bytes queued for sending.

Definition at line 1651 of file unified_network.cpp.

References _CbServer, _IdCnx, _UsedConnection, NLNET::CCallbackServer::getSendQueueSize(), and NLNET::CUnifiedNetwork::CUnifiedConnection::Ready.

std::string NLNET::CUnifiedNetwork::getServiceName ( TServiceId  sid  ) 

Return the name of the specified service, or "" if not found.

Definition at line 1803 of file unified_network.cpp.

References getUnifiedConnection(), and NLNET::CUnifiedNetwork::CUnifiedConnection::ServiceName.

Referenced by NLNET::CGatewayL5Transport::open().

std::string NLNET::CUnifiedNetwork::getServiceUnifiedName ( TServiceId  sid  ) 

Return a string identifying the service, using the format "NAME-sid" (or "sid" only if not found).

Definition at line 1816 of file unified_network.cpp.

References NLNET::TServiceId::get(), getUnifiedConnection(), NLNET::CUnifiedNetwork::CUnifiedConnection::ServiceName, and NLMISC::toString().

CUnifiedNetwork::CUnifiedConnection * NLNET::CUnifiedNetwork::getUnifiedConnection ( TServiceId  sid,
bool  warn = true 
) [private]
bool NLNET::CUnifiedNetwork::haveNamedCnx ( const std::string &  name,
TServiceId  sid 
) [private]

Definition at line 1999 of file unified_network.cpp.

References _NamedCnx.

Referenced by autoReconnect().

bool NLNET::CUnifiedNetwork::init ( const CInetAddress addr,
CCallbackNetBase::TRecordingState  rec,
const std::string &  shortName,
uint16  port,
TServiceId sid 
)

Creates the connection to the Naming Service.

If the connection failed, ESocketConnectionFailed exception is generated. This function is called automatically called by the service class at the beginning.

Parameters:
addr address of the naming service (0 is you don't want to use the naming service)
rec recording state to know if we have to record or replay messages
Returns:
false if the instance startup was denied by the naming service

Init the main pipe to select() on data available

Definition at line 534 of file unified_network.cpp.

References _CbServer, _Initialised, _MainDataAvailablePipe, _Name, _NamingServiceAddr, _RecordingState, _ServerPort, _SId, NLNET::CCallbackNetBase::addCallbackArray(), NLNET::AliveThread, AUTOCHECK_DISPLAY, connect(), NLNET::CNamingClient::connected(), NLNET::TServiceId::get(), NLMISC::getThreadId(), NLNET::CBufServer::init(), NLNET::CInetAddress::isValid(), NLNET::CInetAddress::localAddresses(), nlassert, nlinfo, NLMISC::nlSleep(), nlwarning, NLNET::CCallbackNetBase::Off, NLNET::CNamingClient::queryServicePort(), NLMISC::ICommandsHandler::registerCommandsHandler(), NLNET::CNamingClient::registerService(), NLNET::CNamingClient::registerServiceWithSId(), NLNET::CCallbackServer::setConnectionCallback(), NLNET::CCallbackNetBase::setDefaultCallback(), NLNET::CCallbackServer::setDisconnectionCallback(), NLNET::CBufNetBase::setExternalPipeForDataAvailable(), NLNET::CNamingClient::setRegistrationBroadcastCallback(), NLNET::CNamingClient::setUnregistrationBroadcastCallback(), NLMISC::IThread::start(), NLNET::ThreadCreator, uncbConnection, uncbDisconnection, uncbMsgProcessing, uNetRegistrationBroadcast, uNetUnregistrationBroadcast, and NLNET::unServerCbArray.

bool NLNET::CUnifiedNetwork::isConnectionConnected ( TServiceId  sid  )  const

Return the state of the connection (return true if the connection is fully connected).

Definition at line 1257 of file unified_network.cpp.

References _IdCnx, NLNET::TServiceId::get(), and NLNET::CUnifiedNetwork::CUnifiedConnection::Ready.

Referenced by NLNET::CGatewayL5Transport::open().

bool NLNET::CUnifiedNetwork::isServiceLocal ( const std::string &  serviceName  ) 

Returns true if the serviceName service is on the same computer than this service.

Definition at line 1754 of file unified_network.cpp.

References _Name, _NamedCnx, and isServiceLocal().

bool NLNET::CUnifiedNetwork::isServiceLocal ( TServiceId  sid  ) 

Returns true if the sid service is on the same computer than this service.

Definition at line 1772 of file unified_network.cpp.

References _IdCnx, _SId, NLNET::TServiceId::get(), NLNET::CInetAddress::localAddresses(), and NLNET::CUnifiedNetwork::CUnifiedConnection::Ready.

Referenced by isServiceLocal().

bool NLNET::CUnifiedNetwork::isUsed (  )  [static]

Returns the singleton instance of the CUnifiedNetwork class.

Returns true if the application called getInstance(). This function is used to know if the user is using layer 4 or layer 5

Definition at line 1834 of file unified_network.cpp.

Referenced by NLNET::NLMISC_CATEGORISED_DYNVARIABLE().

NLMISC_COMMAND_HANDLER_TABLE_END NLNET::CUnifiedNetwork::NLMISC_CLASS_COMMAND_DECL ( addService   )  [private]
NLNET::CUnifiedNetwork::NLMISC_SAFE_SINGLETON_DECL_PTR ( CUnifiedNetwork   )  [private]
void NLNET::CUnifiedNetwork::release ( bool  mustFlushSendQueues = true,
const std::vector< std::string > &  namesOfOnlyServiceToFlushSending = std::vector<std::string>() 
)

Closes the connection to the naming service, every other connection and free.

Parameters:
mustFlushSendQueues If true, all send queues or only queues in namesOfOnlyServiceToFlushSending will be really sent before disconnecting. In some cases disconnect(true) can take a while.
namesOfOnlyServiceToFlushSending When mustFlushSendQueues is true, this param can hold a list of service short names. Only the send queues to the services specified will be flushed (and waited) at exit. If the list is empty (and mustFlushSendQueues is true), all the queues will be flushed (and waited). See also "Handling network congestion" in CUnifiedNetwork above comments, and tryFlushAllQueues().

Definition at line 680 of file unified_network.cpp.

References _Callbacks, _CbServer, _DownCallbacks, _IdCnx, _Initialised, _MainDataAvailablePipe, _NamedCnx, _UpCallbacks, _UsedConnection, NLNET::AliveThread, NLNET::CNamingClient::connected(), NLNET::CNamingClient::disconnect(), NLNET::CCallbackServer::disconnect(), NLNET::CAliveCheck::ExitRequired, NLMISC::getThreadId(), NLNET::InvalidSockId, nldebug, nlinfo, NLMISC::nlSleep(), nlwarning, NLNET::CUnifiedNetwork::CUnifiedConnection::NotUsed, NLNET::PipeRead, NLNET::PipeWrite, NLNET::CAliveCheck::Thread, NLNET::ThreadCreator, tryFlushAllQueues(), NLMISC::ICommandsHandler::unregisterCommandsHandler(), and NLMISC::IThread::wait().

void NLNET::CUnifiedNetwork::removeNamedCnx ( const std::string &  name,
TServiceId  sid 
) [private]

Definition at line 2038 of file unified_network.cpp.

References _NamedCnx, AUTOCHECK_DISPLAY, and NLNET::TServiceId::get().

Referenced by NLNET::uncbDisconnection().

void NLNET::CUnifiedNetwork::removeServiceDownCallback ( const std::string &  serviceName,
TUnifiedNetCallback  cb,
void *  arg = 0 
)

Remove a service down callback.

Definition at line 1560 of file unified_network.cpp.

References _DownCallbacks, _DownUniCallback, and nlwarning.

void NLNET::CUnifiedNetwork::removeServiceUpCallback ( const std::string &  serviceName,
TUnifiedNetCallback  cb,
void *  arg = 0 
)

Remove a service up callback.

Definition at line 1489 of file unified_network.cpp.

References _UpCallbacks, _UpUniCallback, and nlwarning.

bool NLNET::CUnifiedNetwork::send ( TServiceId  serviceId,
const CMessage msg,
uint8  nid = 0xFF 
)

Sends a message to a specific serviceId.

Parameters:
serviceId Id of the service you want to send the message.
msg the message you want to send.
nid Network Id specify to which network the message must pass throw (0xFF mean the default network)
Returns:
true if the service was found (may return true even if the sending failed)

Definition at line 1371 of file unified_network.cpp.

References _IdCnx, _Initialised, findConnectionId(), NLNET::TServiceId::get(), NLNET::CMessage::getName(), NLMISC::getThreadId(), nlassertex, nlwarning, NLNET::CUnifiedNetwork::CUnifiedConnection::Ready, and NLNET::ThreadCreator.

uint NLNET::CUnifiedNetwork::send ( const std::string &  serviceName,
const CMessage msg,
bool  warnIfNotFound = true,
uint8  nid = 0xFF 
)

Sends a message to a specific serviceName.

If there's more than one service with this name, all services of this name will receive the message.

Parameters:
serviceName name of the service you want to send the message (may not be unique.)
msg the message you want to send.
nid Network Id specify to which network the message must pass throw (0xFF mean the default network)
Returns:
the number of service instances found (may be counter even if the sending failed)

Definition at line 1328 of file unified_network.cpp.

References _IdCnx, _Initialised, _NamedCnx, findConnectionId(), NLNET::TServiceId::get(), NLNET::CMessage::getName(), NLMISC::getThreadId(), nlassertex, nlwarning, NLNET::CUnifiedNetwork::CUnifiedConnection::Ready, and NLNET::ThreadCreator.

void NLNET::CUnifiedNetwork::sendAll ( const CMessage msg,
uint8  nid = 0xFF 
)

Broadcasts a message to all connected services.

Parameters:
msg the message you want to send.
nid Network Id specify to which network the message must pass throw (0xFF mean the default network)

Definition at line 1395 of file unified_network.cpp.

References _IdCnx, _Initialised, findConnectionId(), NLMISC::getThreadId(), nlassertex, nlwarning, NLNET::CUnifiedNetwork::CUnifiedConnection::Ready, and NLNET::ThreadCreator.

void NLNET::CUnifiedNetwork::setServiceDownCallback ( const std::string &  serviceName,
TUnifiedNetCallback  cb,
void *  arg = 0,
bool  back = true 
)

Sets callback for disconnections.

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.

You can set more than one callback, each one will be called one after one. If the serviceName is "*", the callback will be call for any services, including 'external' services (i.e. services not in the NS address space, usually connected by calling addService() manually) If you set the same callback for a specific service S and for "*", the callback might be called twice (in case the service S is down)

Parameters:
back if true, put the callback at the end of the callback array, otherwise but on the beginning. You should always use true

Definition at line 1541 of file unified_network.cpp.

References _DownCallbacks, _DownUniCallback, and nlassert.

Referenced by NLNET::CGatewayL5Transport::open().

void NLNET::CUnifiedNetwork::setServiceUpCallback ( const std::string &  serviceName,
TUnifiedNetCallback  cb,
void *  arg = 0,
bool  back = true 
)

Sets callback for incoming connections.

On a client, the callback will be called 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

You can set more than one callback, each one will be called one after one. If the serviceName is "*", the callback will be call for any services, including 'external' services (i.e. services not in the NS address space, usually connected by calling addService() manually) If you set the same callback for a specific service S and for "*", the callback might be called twice (in case the service S is up)

Parameters:
back if true, put the callback at the end of the callback array, otherwise but on the beginning. You should always use true

Definition at line 1470 of file unified_network.cpp.

References _UpCallbacks, _UpUniCallback, and nlassert.

Referenced by NLNET::CGatewayL5Transport::open().

void NLNET::CUnifiedNetwork::sleepUntilDataAvailable ( NLMISC::TTime  msecMax  )  [protected]

Sleep (implemented by select()).

uint NLNET::CUnifiedNetwork::tryFlushAllQueues ( const std::vector< std::string > &  namesOfOnlyServiceToFlushSending = std::vector<std::string>()  ) 

Flush all or part of the sending queues, and report the number of bytes still pending.

To ensure manually all data are sent before stopping a service, you may want to repeat calling this method evenly until it returns 0. The default release(false) of CUnifiedNetwork only flushes each connection once, but if the network is congested (when there are big streams to send) the first flush may not succeed to send entire buffers.

Parameters:
namesOfOnlyServiceToFlushSending If not empty, only the send queues to the services specified (by short name) will be flushed. See also "Handling network congestion" in CUnifiedNetwork above comments.

Definition at line 1424 of file unified_network.cpp.

References _IdCnx, _UsedConnection, NLNET::CUnifiedNetwork::CUnifiedConnection::Connections, H_AUTO, nlassert, NLNET::CUnifiedNetwork::CUnifiedConnection::Ready, NLNET::CUnifiedNetwork::CUnifiedConnection::ServiceName, and NLNET::CUnifiedNetwork::CUnifiedConnection::State.

Referenced by release().

void NLNET::CUnifiedNetwork::update ( NLMISC::TTime  timeout = 0  ) 

Call it evenly.

the parameter select the timeout value in seconds 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).


Friends And Related Function Documentation

friend struct nel_isServiceLocalClass [friend]

Definition at line 753 of file unified_network.h.

friend struct nel_l5CallbackClass [friend]

Definition at line 754 of file unified_network.h.

friend struct nel_l5QueuesStatsClass [friend]

Definition at line 755 of file unified_network.h.

void uncbConnection ( TSockId  from,
void *  arg 
) [friend]

Definition at line 170 of file unified_network.cpp.

Referenced by init().

void uncbDisconnection ( TSockId  from,
void *  arg 
) [friend]

Definition at line 177 of file unified_network.cpp.

Referenced by addService(), and init().

void uncbMsgProcessing ( CMessage msgin,
TSockId  from,
CCallbackNetBase netbase 
) [friend]

Definition at line 348 of file unified_network.cpp.

Referenced by addService(), and init().

void uncbServiceIdentification ( CMessage msgin,
TSockId  from,
CCallbackNetBase netbase 
) [friend]

Definition at line 255 of file unified_network.cpp.

void uNetRegistrationBroadcast ( const std::string &  name,
TServiceId  sid,
const std::vector< CInetAddress > &  addr 
) [friend]

Definition at line 79 of file unified_network.cpp.

Referenced by init().

void uNetUnregistrationBroadcast ( const std::string &  name,
TServiceId  sid,
const std::vector< CInetAddress > &  addr 
) [friend]

Definition at line 116 of file unified_network.cpp.

Referenced by init().


Member Data Documentation

Map of callbacks.

Definition at line 680 of file unified_network.h.

Referenced by addCallbackArray(), findCallback(), release(), and NLNET::uncbMsgProcessing().

The callback server.

Definition at line 665 of file unified_network.h.

Referenced by getBytesReceived(), getBytesSent(), getReceiveQueueSize(), getSendQueueSize(), init(), and release().

Vector of closed connection to reset outside of the client update loop.

Definition at line 656 of file unified_network.h.

Referenced by NLNET::uncbDisconnection().

std::vector<std::string> NLNET::CUnifiedNetwork::_DefaultNetwork [private]

for each services, which network to take

Definition at line 704 of file unified_network.h.

Referenced by addDefaultNetwork(), addService(), clearDefaultNetwork(), and NLNET::uncbServiceIdentification().

Used for external service.

Definition at line 686 of file unified_network.h.

Referenced by addService().

true if initialization function called

Definition at line 715 of file unified_network.h.

Referenced by addService(), connect(), getNetBase(), init(), release(), send(), and sendAll().

Last time of retry.

Definition at line 689 of file unified_network.h.

Pipe to select() on data available (shared among all connections).

Definition at line 708 of file unified_network.h.

Referenced by addService(), init(), and release().

std::string NLNET::CUnifiedNetwork::_Name [private]

Service name.

Definition at line 677 of file unified_network.h.

Referenced by addService(), autoReconnect(), init(), and isServiceLocal().

Map of connections by service name.

Definition at line 662 of file unified_network.h.

Referenced by addNamedCnx(), autoCheck(), displayInternalTables(), getNetBase(), haveNamedCnx(), isServiceLocal(), release(), removeNamedCnx(), and send().

The main instance.

Naming service

Definition at line 698 of file unified_network.h.

Referenced by init().

Time of the theoretical next update.

Definition at line 692 of file unified_network.h.

Recording state.

Definition at line 674 of file unified_network.h.

Referenced by init().

The server port.

Definition at line 683 of file unified_network.h.

Referenced by init().

Service id of the running service.

Definition at line 712 of file unified_network.h.

Referenced by addService(), autoReconnect(), connect(), init(), and isServiceLocal().

Map of the up/down service callbacks.

Definition at line 668 of file unified_network.h.

Referenced by callServiceUpCallback(), release(), removeServiceUpCallback(), and setServiceUpCallback().

This vector contains only an index to the unified connection. It is used to have quick access on the available connections.

Definition at line 659 of file unified_network.h.

Referenced by addService(), autoCheck(), displayInternalTables(), getBytesReceived(), getBytesSent(), getConnectionList(), getReceiveQueueSize(), getSendQueueSize(), release(), tryFlushAllQueues(), and NLNET::uncbServiceIdentification().


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

Generated on Thu Jan 7 08:30:21 2010 for NeL by  doxygen 1.6.1