NLNET::CCallbackClient Class Reference

#include <callback_client.h>

Inheritance diagram for NLNET::CCallbackClient:

NLNET::CCallbackNetBase NLNET::CBufClient NLNET::CBufNetBase

Detailed Description

Client class for layer 3
Author:
Vianney Lecroart, Olivier Cado

Nevrax France

Date:
2001

Definition at line 46 of file callback_client.h.

Public Types

enum  TEventType { User = 'U', Connection = 'C', Disconnection = 'D' }
 Type of incoming events (max 256). More...

enum  TRecordingState { Off, Record, Replay }

Public Member Functions

void addCallbackArray (const TCallbackItem *callbackarray, NLMISC::CStringIdArray::TStringId arraysize)
void authorizeOnly (const char *callbackName, TSockId hostid=InvalidSockId)
uint64 bytesDownloaded () const
 Returns the number of bytes downloaded (read or still in the receive buffer) since the latest connection.

uint64 bytesUploaded () const
 Returns the number of bytes uploaded (flushed) since the latest connection.

 CCallbackClient (TRecordingState rec=Off, const std::string &recfilename="", bool recordall=true)
 Constructor.

void connect (const CInetAddress &addr)
 Connects to the specified host.

virtual bool connected () const
void disconnect (bool quick=false)
void disconnect (TSockId hostid=InvalidSockId)
void displayAllMyAssociations ()
void displayReceiveQueueStat (NLMISC::CLog *log=NLMISC::InfoLog)
void displaySendQueueStat (NLMISC::CLog *log=NLMISC::InfoLog)
void displaySendQueueStat (NLMISC::CLog *log=NLMISC::InfoLog, TSockId destid=InvalidSockId)
void displayThreadStat (NLMISC::CLog *log=NLMISC::InfoLog)
bool flush ()
bool flush (TSockId hostid=InvalidSockId)
 Force to send all data pending in the send queue.

uint64 getBytesReceived ()
uint64 getBytesSent ()
uint64 getReceiveQueueSize ()
uint32 getSendQueueSize () const
uint64 getSendQueueSize ()
NLMISC::CStringIdArraygetSIDA ()
 Use this function to get the String ID Array needed when you want to create a message.

virtual TSockId getSockId (TSockId hostid=InvalidSockId)
 Returns the sockid.

virtual const CInetAddresshostAddress (TSockId hostid)
 Returns the address of the specified host.

TSockId id () const
 Returns the id of the connection.

void ignoreAllUnknownId (bool b)
bool isAServer () const
 Returns true if this is a CCallbackServer.

uint32 maxExpectedBlockSize () const
 Returns the max size of the received messages (default: 2^31-1).

uint32 maxSentBlockSize () const
 Returns the max size of the sent messages (default: 2^31-1).

uint64 newBytesDownloaded ()
 Returns the number of bytes downloaded since the previous call to this method.

uint64 newBytesUploaded ()
 Returns the number of bytes uploaded since the previous call to this method.

void receive (NLMISC::CMemStream &buffer)
const CInetAddressremoteAddress () const
 Returns the address of the remote host.

void send (const CMessage &buffer, TSockId hostid=InvalidSockId, bool log=true)
 Sends a message to the remote host (the second parameter isn't used).

void sendAllMyAssociations (TSockId to)
 Used by client and server class.

void setDefaultCallback (TMsgCallback defaultCallback)
 Sets default callback for unknown message types.

void setDisconnectionCallback (TNetCallback cb, void *arg)
 Sets callback for disconnections (or NULL to disable callback).

void setMaxExpectedBlockSize (sint32 limit)
void setMaxSentBlockSize (sint32 limit)
void setOtherSideAssociations (const char **associationarray, NLMISC::CStringIdArray::TStringId arraysize)
void setSizeFlushTrigger (sint32 size)
void setTimeFlushTrigger (sint32 ms)
void update ()
 Update the network (call this method evenly).

void update (sint32 timeout=0)
 Updates the network (call this method evenly).


Protected Member Functions

void * argOfDisconnectionCallback () const
 Returns the argument of the disconnection callback.

void baseUpdate (sint32 timeout=0)
 Used by client and server class.

void checkThreadId () const
volatile bool dataAvailableFlag () const
 Return _DataAvailable.

TNetCallback disconnectionCallback () const
 Returns the disconnection callback.

void processOneMessage ()
 Read a message from the network and process it.

void pushMessageIntoReceiveQueue (const uint8 *buffer, uint32 size)
void pushMessageIntoReceiveQueue (const std::vector< uint8 > &buffer)
 Push message into receive queue (mutexed).

CSynchronizedFIFOreceiveQueue ()
 Access to the receive queue.

void setDataAvailableFlag (bool da)
 Sets _DataAvailable.


Protected Attributes

CNonBlockingBufSock_BufSock
 Send buffer and connection.

uint64 _BytesReceived
uint64 _BytesSent
std::vector< TCallbackItem_CallbackArray
TMsgCallback _DefaultCallback
bool _FirstUpdate
NLMISC::CStringIdArray _InputSIDA
bool _IsAServer
TNetCallback _NewDisconnectionCallback
 Used by client and server class.

bool _NoDelay
 True when the Nagle algorithm must be disabled (TCP_NODELAY).

NLMISC::CStringIdArray _OutputSIDA
uint64 _PrevBytesDownloaded
 Previous number of bytes downloaded.

uint64 _PrevBytesUploaded
 Previous number of bytes uploaded.

uint _ThreadId

Private Member Functions

bool dataAvailable ()
 Returns true if there are messages to read.

void receive (CMessage &buffer, TSockId *hostid=NULL)
 On this layer, you can't call directly receive, It s the update() function that receive and call your callaback.

void send (const NLMISC::CMemStream &buffer)
 These function is public in the base class and put it private here because user cannot use it in layer 2.


Private Attributes

uint32 ReceiveNextValue
uint32 SendNextValue

Friends

class CClientReceiveTask
class NLNET::CBufSock


Member Enumeration Documentation

enum NLNET::CBufNetBase::TEventType [inherited]
 

Type of incoming events (max 256).

Enumeration values:
User 
Connection 
Disconnection 

Definition at line 79 of file buf_net_base.h.

00079 { User = 'U', Connection = 'C', Disconnection = 'D' };

enum NLNET::CCallbackNetBase::TRecordingState [inherited]
 

Enumeration values:
Off 
Record 
Replay 

Definition at line 163 of file callback_net_base.h.

00163 { Off, Record, Replay };


Constructor & Destructor Documentation

NLNET::CCallbackClient::CCallbackClient TRecordingState  rec = Off,
const std::string &  recfilename = "",
bool  recordall = true
 

Constructor.

Definition at line 59 of file callback_client.cpp.

References NLNET::CCallbackNetBase::addCallbackArray(), NLNET::ClientMessageAssociationArray, and NLMISC::CStringIdArray::ignoreAllUnknownId().

00059                                                                                                     :
00060         CCallbackNetBase( rec, recfilename, recordall ), CBufClient( true, rec==Replay ), SendNextValue(0), ReceiveNextValue(0)
00061 {
00062         CBufClient::setDisconnectionCallback (_NewDisconnectionCallback, this);
00063 
00064         // add the callback needed to associate messages with id
00065         addCallbackArray (ClientMessageAssociationArray, sizeof (ClientMessageAssociationArray) / sizeof (ClientMessageAssociationArray[0]));
00066 
00067         _InputSIDA.ignoreAllUnknownId (true);
00068 
00069         _IsAServer = false;
00070         _DefaultCallback = NULL;
00071 }


Member Function Documentation

void NLNET::CCallbackNetBase::addCallbackArray const TCallbackItem callbackarray,
NLMISC::CStringIdArray::TStringId  arraysize
[inherited]
 

Appends callback array with the specified array. You can add callback only *after* adding the server or the client.

Parameters:
arraysize is the number of callback items.

Definition at line 184 of file callback_net_base.cpp.

References NLNET::CCallbackNetBase::_CallbackArray, NLNET::CCallbackNetBase::_OutputSIDA, NLMISC::CStringIdArray::addString(), NLNET::TCallbackItem::Callback, NLNET::CCallbackNetBase::checkThreadId(), nlassert, NLMISC::CStringIdArray::resize(), sint, NLMISC::CStringIdArray::size(), NLMISC::CStringIdArray::TStringId, and uint.

Referenced by CCallbackClient(), NLNET::CCallbackNetBase::CCallbackNetBase(), NLNET::CPacsClient::connect(), NLNET::CNamingClient::connect(), NLNET::CLoginClient::connectToShard(), NLNET::CUnifiedNetwork::init(), NLNET::CLoginServer::init(), and NLNET::_CUniTime::installServer().

00185 {
00186         checkThreadId ();
00187 
00188         // be sure that the 2 array have the same size
00189         nlassert (_CallbackArray.size () == (uint)_OutputSIDA.size ());
00190 
00191         if (arraysize == 1 && callbackarray[0].Callback == NULL && string("") == callbackarray[0].Key)
00192         {
00193                 // it's an empty array, ignore it
00194                 return;
00195         }
00196 
00197         // resize the array
00198         sint oldsize = _CallbackArray.size();
00199 
00200         _CallbackArray.resize (oldsize + arraysize);
00201         _OutputSIDA.resize (oldsize + arraysize);
00202 
00203 //TOO MUCH MESSAGE      nldebug ("L3NB_CB: Adding %d callback to the array", arraysize);
00204 
00205         for (sint i = 0; i < arraysize; i++)
00206         {
00207                 CStringIdArray::TStringId ni = oldsize + i;
00208 //TOO MUCH MESSAGE              nldebug ("L3NB_CB: Adding callback to message '%s', id '%d'", callbackarray[i].Key, ni);
00209                 // copy callback value
00210                 
00211                 _CallbackArray[ni] = callbackarray[i];
00212                 // add the string to the string id array
00213                 _OutputSIDA.addString (callbackarray[i].Key, ni);
00214 
00215         }
00216 //      nldebug ("LNETL3NB_CB: Added %d callback Now, there're %d callback associated with message type", arraysize, _CallbackArray.size ());
00217 }

void* NLNET::CBufNetBase::argOfDisconnectionCallback  )  const [inline, protected, inherited]
 

Returns the argument of the disconnection callback.

Definition at line 160 of file buf_net_base.h.

References NLNET::CBufNetBase::_DisconnectionCbArg.

Referenced by NLNET::CBufServer::dataAvailable(), and NLNET::CBufClient::dataAvailable().

00160 { return _DisconnectionCbArg; }

void NLNET::CCallbackNetBase::authorizeOnly const char *  callbackName,
TSockId  hostid = InvalidSockId
[inherited]
 

Sets the callback that you want the other side calls. If it didn't call this callback, it will be disconnected If cb is NULL, we authorize *all* callback. On a client, the hostid must be InvalidSockId (or ommited). On a server, you must provide a hostid.

Definition at line 471 of file callback_net_base.cpp.

References NLNET::CBufSock::asString(), NLNET::CBufSock::AuthorizedCallback, NLNET::CCallbackNetBase::checkThreadId(), NLNET::CCallbackNetBase::getSockId(), nlassert, nldebug, and NLNET::TSockId.

Referenced by NLNET::cbShardValidation(), and NLNET::ClientConnection().

00472 {
00473         checkThreadId ();
00474 
00475         nldebug ("LNETL3NB: authorizeOnly (%s, %s)", callbackName, hostid->asString().c_str());
00476 
00477         hostid = getSockId (hostid);
00478         
00479         nlassert (hostid != InvalidSockId);
00480 
00481         hostid->AuthorizedCallback = (callbackName == NULL)?"":callbackName;
00482 }

void NLNET::CCallbackNetBase::baseUpdate sint32  timeout = 0  )  [protected, inherited]
 

Used by client and server class.

Definition at line 328 of file callback_net_base.cpp.

References NLNET::CCallbackNetBase::_FirstUpdate, NLNET::CCallbackNetBase::_InputSIDA, NLNET::CCallbackNetBase::_LastMovedStringArray, NLNET::CCallbackNetBase::_LastUpdateTime, NLNET::CCallbackNetBase::checkThreadId(), NLNET::CCallbackNetBase::dataAvailable(), NLMISC::CStringIdArray::getAskedStringArray(), NLMISC::CStringIdArray::getNeedToAskedStringArray(), H_AUTO, NLMISC::CStringIdArray::moveNeedToAskToAskedStringArray(), nlassert, nldebug, NLMISC::nlSleep(), NLNET::CCallbackNetBase::processOneMessage(), NLNET::CCallbackNetBase::send(), NLMISC::CMemStream::serial(), sint32, size, NLMISC::CStringIdArray::TStringId, and NLMISC::TTime.

Referenced by NLNET::CCallbackServer::update(), and update().

00329 {
00330         H_AUTO(L3UpdateCallbackNetBase);
00331 
00332         checkThreadId ();
00333 
00334         // slow down the layer H_AUTO (CCallbackNetBase_baseUpdate);
00335 
00336         nlassert( timeout >= -1 );
00337         TTime t0 = CTime::getLocalTime();
00338 
00339         //
00340         // The first time, we init time counters
00341         //
00342         if (_FirstUpdate)
00343         {
00344 //              nldebug("LNETL3NB: First update()");
00345                 _FirstUpdate = false;
00346                 _LastUpdateTime = t0;
00347                 _LastMovedStringArray = t0;
00348         }
00349 
00350         //
00351         // Every 1 seconds if we have new unknown association, we ask them to the other side
00352         //
00353         if (t0 - _LastUpdateTime >  1000)
00354         {
00355 //              nldebug("LNETL3NB: baseUpdate()");
00356                 _LastUpdateTime = t0;
00357 
00358                 const set<string> &sa = _InputSIDA.getNeedToAskedStringArray ();
00359                 if (!sa.empty ())
00360                 {
00361                         CMessage msgout (_InputSIDA, "AA");
00362                         //nlassert (sa.size () < 65536); // no size limit anymore
00363                         CStringIdArray::TStringId size = sa.size ();
00364                         nldebug ("LNETL3NB_ASSOC: I need %d string association, ask them to the other side", size);
00365                         msgout.serial (size);
00366                         for (set<string>::iterator it = sa.begin(); it != sa.end(); it++)
00367                         {
00368                                 nldebug ("LNETL3NB_ASSOC:  what is the id of '%s'?", (*it).c_str ());
00369                                 string str(*it);
00370                                 msgout.serial (str);
00371                         }
00372                         // send the message to the other side
00373                         send (msgout, 0);
00374                         _InputSIDA.moveNeedToAskToAskedStringArray();
00375                         _LastMovedStringArray = t0;
00376                 }
00377         }
00378 
00379         //
00380         // Every 60 seconds if we have not answered association, we ask again to get them!
00381         //
00382         if (!_InputSIDA.getAskedStringArray().empty() && t0 - _LastMovedStringArray > 60000)
00383         {
00384                 // we didn't have an answer for the association, resend them
00385                 const set<string> sa = _InputSIDA.getAskedStringArray ();
00386                 CMessage msgout (_InputSIDA, "AA");
00387                 //nlassert (sa.size () < 65536); // no size limit anymore
00388                 CStringIdArray::TStringId size = sa.size ();
00389                 nldebug ("LNETL3NB_ASSOC: client didn't answer my asked association, retry! I need %d string association, ask them to the other side", size);
00390                 msgout.serial (size);
00391                 for (set<string>::iterator it = sa.begin(); it != sa.end(); it++)
00392                 {
00393                         nldebug ("LNETL3NB_ASSOC:  what is the id of '%s'?", (*it).c_str ());
00394                         string str(*it);
00395                         msgout.serial (str);
00396                 }
00397                 // sends the message to the other side
00398                 send (msgout, 0);
00399                 _LastMovedStringArray = t0;
00400         }
00401 
00402         /*
00403          * timeout -1    =>  read one message in the queue or nothing if no message in queue
00404          * timeout 0     =>  read all messages in the queue
00405          * timeout other =>  read all messages in the queue until timeout expired (at least all one time)
00406          */
00407 
00408         bool exit = false;
00409 
00410         while (!exit)
00411         {
00412                 // process all messages in the queue
00413                 while (dataAvailable ())
00414                 {
00415                         processOneMessage ();
00416                         if (timeout == -1)
00417                         {
00418                                 exit = true;
00419                                 break;
00420                         }
00421                 }
00422 
00423                 // need to exit?
00424                 if (timeout == 0 || (sint32)(CTime::getLocalTime() - t0) > timeout)
00425                 {
00426                         exit = true;
00427                 }
00428                 else
00429                 {
00430                         // enable multithreading on windows :-/
00431                         // slow down the layer H_AUTO (CCallbackNetBase_baseUpdate_nlSleep);
00432                         nlSleep (10);
00433                 }
00434         }
00435 
00436 #ifdef USE_MESSAGE_RECORDER
00437         _MR_UpdateCounter++;
00438 #endif
00439 
00440 }

uint64 NLNET::CBufClient::bytesDownloaded  )  const [inline, inherited]
 

Returns the number of bytes downloaded (read or still in the receive buffer) since the latest connection.

Definition at line 172 of file buf_client.h.

References NLNET::CBufClient::_BufSock, NLNET::CSock::bytesReceived(), NLNET::CBufSock::Sock, and uint64.

Referenced by NLNET::CBufClient::newBytesDownloaded().

00172 { return _BufSock->Sock->bytesReceived(); }

uint64 NLNET::CBufClient::bytesUploaded  )  const [inline, inherited]
 

Returns the number of bytes uploaded (flushed) since the latest connection.

Definition at line 175 of file buf_client.h.

References NLNET::CBufClient::_BufSock, NLNET::CSock::bytesSent(), NLNET::CBufSock::Sock, and uint64.

Referenced by NLNET::CBufClient::newBytesUploaded().

00175 { return _BufSock->Sock->bytesSent(); }

void NLNET::CCallbackNetBase::checkThreadId  )  const [protected, inherited]
 

Definition at line 533 of file callback_net_base.cpp.

Referenced by NLNET::CCallbackNetBase::addCallbackArray(), NLNET::CCallbackNetBase::authorizeOnly(), NLNET::CCallbackNetBase::baseUpdate(), connect(), NLNET::CCallbackServer::connected(), connected(), NLNET::CCallbackServer::dataAvailable(), dataAvailable(), NLNET::CCallbackServer::disconnect(), disconnect(), NLNET::CCallbackNetBase::displayAllMyAssociations(), NLNET::CCallbackServer::flush(), flush(), NLNET::CCallbackServer::getSockId(), getSockId(), NLNET::CCallbackServer::hostAddress(), NLNET::CCallbackNetBase::isAServer(), NLNET::CCallbackNetBase::processOneMessage(), NLNET::CCallbackServer::receive(), receive(), NLNET::CCallbackServer::send(), send(), NLNET::CCallbackServer::sendAllMyAssociations(), NLNET::CCallbackServer::setConnectionCallback(), NLNET::CCallbackServer::setDisconnectionCallback(), NLNET::CCallbackNetBase::setDisconnectionCallback(), setDisconnectionCallback(), NLNET::CCallbackNetBase::setOtherSideAssociations(), NLNET::CCallbackServer::update(), and update().

00534 {
00535 /*      some people use this class in different thread but with a mutex to be sure to have
00536         no concurent access
00537         if (getThreadId () != _ThreadId)
00538         {
00539                 nlerror ("You try to access to the same CCallbackClient or CCallbackServer with 2 differents thread (%d and %d)", _ThreadId, getThreadId());
00540         }
00541 */
00542 }

void NLNET::CCallbackClient::connect const CInetAddress addr  ) 
 

Connects to the specified host.

Reimplemented from NLNET::CBufClient.

Definition at line 286 of file callback_client.cpp.

References addr, NLNET::CCallbackNetBase::checkThreadId(), NLNET::CBufSock::connect(), NLNET::CSock::connected(), NLNET::Connecting, NLNET::ConnFailing, NL_I64, nlassert, nlwarning, NLMISC::CMemStream::serial(), NLNET::CBufSock::Sock, and NLNET::TNetworkEvent.

Referenced by NLNET::CUnifiedNetwork::addService(), NLNET::CNamingClient::connect(), NLNET::CLoginClient::connectToShard(), NLNET::CNetManager::createConnection(), NLNET::CNamingClient::lookupAndConnect(), NLNET::CNetDisplayer::setLogServer(), NLNET::CUnifiedNetwork::update(), and NLNET::CNetManager::update().

00287 {
00288         checkThreadId ();
00289 
00290         SendNextValue = ReceiveNextValue = 0;
00291 
00292 #ifdef USE_MESSAGE_RECORDER
00293         if ( _MR_RecordingState != Replay )
00294         {
00295                 try
00296                 {
00297 #endif
00298 
00299                         // Connect
00300                         CBufClient::connect( addr );
00301 
00302 #ifdef USE_MESSAGE_RECORDER
00303                         if ( _MR_RecordingState == Record )
00304                         {
00305                                 // Record connection
00306                                 CMessage addrmsg;
00307                                 addrmsg.serial( const_cast<CInetAddress&>(addr) );
00308                                 _MR_Recorder.recordNext( _MR_UpdateCounter, Connecting, _BufSock, addrmsg );
00309                         }
00310                 }
00311                 catch ( ESocketConnectionFailed& )
00312                 {
00313                         if ( _MR_RecordingState == Record )
00314                         {
00315                                 // Record connection
00316                                 CMessage addrmsg;
00317                                 addrmsg.serial( const_cast<CInetAddress&>(addr) );
00318                                 _MR_Recorder.recordNext( _MR_UpdateCounter, ConnFailing, _BufSock, addrmsg );
00319                         }
00320                         throw;
00321                 }
00322         }
00323         else
00324         {
00325                 // Check the connection : failure or not
00326                 TNetworkEvent event = _MR_Recorder.replayConnectionAttempt( addr );
00327                 switch ( event )
00328                 {
00329                 case Connecting :
00330                         // Set the remote address
00331                         nlassert( ! _BufSock->Sock->connected() );
00332                         _BufSock->connect( addr, _NoDelay, true );
00333                         _PrevBytesDownloaded = 0;
00334                         _PrevBytesUploaded = 0;
00335                         /*_PrevBytesReceived = 0;
00336                         _PrevBytesSent = 0;*/
00337                         break;
00338                 case ConnFailing :
00339                         throw ESocketConnectionFailed( addr );
00340                         //break;
00341                 default :
00342                         nlwarning( "LNETL3C: No connection event in replay data, at update #%"NL_I64"u", _MR_UpdateCounter );
00343                 }
00344         }
00345 #endif
00346 }

virtual bool NLNET::CCallbackClient::connected  )  const [inline, virtual]
 

Returns true if the connection is still connected (changed when a disconnection event has reached the front of the receive queue, just before calling the disconnection callback if there is one)

Reimplemented from NLNET::CBufClient.

Definition at line 69 of file callback_client.h.

References NLNET::CCallbackNetBase::checkThreadId().

Referenced by NLNET::CPacsClient::connect(), NLNET::CNamingClient::connect(), NLNET::CNetDisplayer::connected(), NLNET::CNamingClient::connected(), NLNET::CLoginClient::connectToShard(), NLNET::CNamingClient::disconnect(), NLNET::CNetDisplayer::doDisplay(), NLNET::CNamingClient::lookup(), NLNET::CNamingClient::lookupAll(), NLNET::CNamingClient::lookupAlternate(), NLNET::CNamingClient::lookupAndConnect(), NLNET::CNamingClient::queryServicePort(), NLNET::CNamingClient::registerService(), NLNET::CNamingClient::registerServiceWithSId(), NLNET::CNamingClient::resendRegisteration(), NLNET::CNetDisplayer::setLogServer(), NLNET::CNamingClient::unregisterAllServices(), NLNET::CNamingClient::unregisterService(), and NLNET::CNamingClient::update().

00069 { checkThreadId (); return CBufClient::connected (); } 

bool NLNET::CCallbackClient::dataAvailable  )  [private]
 

Returns true if there are messages to read.

Reimplemented from NLNET::CBufClient.

Definition at line 192 of file callback_client.cpp.

References NLNET::CCallbackNetBase::checkThreadId().

00193 {
00194         checkThreadId ();
00195 
00196 #ifdef USE_MESSAGE_RECORDER
00197         if ( _MR_RecordingState != Replay )
00198         {
00199 #endif
00200 
00201                 // Real dataAvailable()
00202                 return CBufClient::dataAvailable (); 
00203 
00204 #ifdef USE_MESSAGE_RECORDER
00205         }
00206         else
00207         {
00208                 // Simulated dataAvailable()
00209                 return CCallbackNetBase::replayDataAvailable();
00210         }
00211 #endif
00212 }

volatile bool NLNET::CBufNetBase::dataAvailableFlag  )  const [inline, protected, inherited]
 

Return _DataAvailable.

Definition at line 206 of file buf_net_base.h.

References NLNET::CBufNetBase::_DataAvailable.

Referenced by NLNET::CBufServer::dataAvailable(), and NLNET::CBufClient::dataAvailable().

00206 { return _DataAvailable; }

void NLNET::CBufClient::disconnect bool  quick = false  )  [inherited]
 

Disconnects the remote host and empties the receive queue. Before that, flushes pending data to send unless quick is true. The disconnection callback will *not* be called. Do not call if the socket is not connected.

Definition at line 318 of file buf_client.cpp.

References NLNET::CBufClient::_BufSock, NLNET::CFifoAccessor, NLNET::CSock::connected(), NLNET::CBufSock::connectedState(), NLNET::CBufSock::disconnect(), NLNET::CBufSock::flush(), nlassert, nlnettrace, NLNET::CBufNetBase::receiveQueue(), NLNET::CBufNetBase::setDataAvailableFlag(), and NLNET::CBufSock::Sock.

Referenced by NLNET::CBufClient::~CBufClient().

00319 {
00320         nlnettrace( "CBufClient::disconnect" );
00321 
00322         // Do not allow to disconnect a socket that is not connected
00323         nlassert( _BufSock->connectedState() );
00324 
00325         // When the NS tells us to remove this connection AND the connection has physically
00326         // disconnected but not yet logically (i.e. disconnection event not processed yet),
00327         // skip flushing and physical active disconnection
00328         if ( _BufSock->Sock->connected() )
00329         {
00330                 // Flush sending is asked for
00331                 if ( ! quick )
00332                 {
00333                         _BufSock->flush();
00334                 }
00335 
00336                 // Disconnect and prevent from advertising the disconnection
00337                 _BufSock->disconnect( false );
00338         }
00339 
00340         // Empty the receive queue
00341         {
00342                 CFifoAccessor recvfifo( &receiveQueue() );
00343                 recvfifo.value().clear();
00344                 setDataAvailableFlag( false );
00345         }
00346 }

void NLNET::CCallbackClient::disconnect TSockId  hostid = InvalidSockId  )  [virtual]
 

Disconnect a connection Unlike in CCallbackClient, you can call disconnect() on a socket that is already disconnected (it will do nothing)

Reimplemented from NLNET::CCallbackNetBase.

Definition at line 354 of file callback_client.cpp.

References NLNET::CCallbackNetBase::checkThreadId(), NLNET::CBufSock::connectedState(), NLNET::Disconnecting, NL_I64, nlassert, nlwarning, and NLNET::TSockId.

Referenced by NLNET::CPacsClient::disconnect(), NLNET::CNamingClient::disconnect(), and NLNET::CNetDisplayer::~CNetDisplayer().

00355 {
00356         nlassert (hostid == InvalidSockId);     // should always be InvalidSockId on client
00357         checkThreadId ();
00358 
00359         SendNextValue = ReceiveNextValue = 0;
00360 
00361         // Disconnect only if connected (same as physically connected for the client)
00362         if ( _BufSock->connectedState() )
00363         {
00364                 
00365 #ifdef USE_MESSAGE_RECORDER
00366                 if ( _MR_RecordingState != Replay )
00367                 {
00368 #endif
00369 
00370                         // Disconnect
00371                         CBufClient::disconnect ();
00372 
00373 #ifdef USE_MESSAGE_RECORDER
00374                 }
00375                 else
00376                 {
00377                         // Read (skip) disconnection in the file
00378                         if ( ! (_MR_Recorder.checkNextOne( _MR_UpdateCounter ) == Disconnecting) )
00379                         {
00380                                 nlwarning( "LNETL3C: No disconnection event in the replay data, at update #%"NL_I64"u", _MR_UpdateCounter );
00381                         }
00382                 }
00383                 // Record or replay disconnection (because disconnect() in the client does not push a disc. event)
00384                 noticeDisconnection( _BufSock );
00385 #endif
00386         }
00387 }

TNetCallback NLNET::CBufNetBase::disconnectionCallback  )  const [inline, protected, inherited]
 

Returns the disconnection callback.

Definition at line 157 of file buf_net_base.h.

References NLNET::CBufNetBase::_DisconnectionCallback, and NLNET::TNetCallback.

Referenced by NLNET::CBufServer::dataAvailable(), and NLNET::CBufClient::dataAvailable().

00157 { return _DisconnectionCallback; }

void NLNET::CCallbackNetBase::displayAllMyAssociations  )  [inherited]
 

Definition at line 464 of file callback_net_base.cpp.

References NLNET::CCallbackNetBase::_OutputSIDA, NLNET::CCallbackNetBase::checkThreadId(), and NLMISC::CStringIdArray::display().

Referenced by NLNET::CLoginClient::connectToShard().

00465 {
00466         checkThreadId ();
00467 
00468         _OutputSIDA.display ();
00469 }

void NLNET::CCallbackClient::displayReceiveQueueStat NLMISC::CLog log = NLMISC::InfoLog  )  [inline, virtual]
 

Implements NLNET::CCallbackNetBase.

Definition at line 88 of file callback_client.h.

00088 { CBufClient::displayReceiveQueueStat(log); }

void NLNET::CBufClient::displaySendQueueStat NLMISC::CLog log = NLMISC::InfoLog  )  [inline, inherited]
 

Definition at line 137 of file buf_client.h.

References NLNET::CBufClient::_BufSock, NLMISC::CBufFIFO::displayStats(), and NLNET::CBufSock::SendFifo.

00138         {
00139                 _BufSock->SendFifo.displayStats(log);
00140         }

void NLNET::CCallbackClient::displaySendQueueStat NLMISC::CLog log = NLMISC::InfoLog,
TSockId  destid = InvalidSockId
[inline, virtual]
 

Implements NLNET::CCallbackNetBase.

Definition at line 89 of file callback_client.h.

References NLNET::TSockId.

00089 { CBufClient::displaySendQueueStat(log); }

void NLNET::CCallbackClient::displayThreadStat NLMISC::CLog log = NLMISC::InfoLog  )  [inline]
 

Reimplemented from NLNET::CBufClient.

Definition at line 91 of file callback_client.h.

00091 { CBufClient::displayThreadStat(log); }

bool NLNET::CBufClient::flush  )  [inline, inherited]
 

Force to send all data pending in the send queue.

Returns:
False if an error has occured (e.g. the remote host is disconnected). To retrieve the reason of the error, call CSock::getLastError() and/or CSock::errorString()

Definition at line 158 of file buf_client.h.

References NLNET::CBufClient::_BufSock, and NLNET::CBufSock::flush().

00158 { return _BufSock->flush(); }

bool NLNET::CCallbackClient::flush TSockId  hostid = InvalidSockId  )  [virtual]
 

Force to send all data pending in the send queue.

Implements NLNET::CCallbackNetBase.

Definition at line 134 of file callback_client.cpp.

References NLNET::CCallbackNetBase::checkThreadId(), nlassert, and NLNET::TSockId.

00135 {
00136         nlassert (hostid == InvalidSockId);     // should always be InvalidSockId on client
00137         checkThreadId ();
00138 
00139 #ifdef USE_MESSAGE_RECORDER
00140         if ( _MR_RecordingState != Replay )
00141         {
00142 #endif
00143 
00144                 // Flush sending (nothing to do in replay mode)
00145                 return CBufClient::flush();
00146                 
00147 #ifdef USE_MESSAGE_RECORDER
00148         }
00149         else
00150         {
00151                 return true;
00152         }
00153 #endif
00154 }

uint64 NLNET::CCallbackNetBase::getBytesReceived  )  [inline, inherited]
 

Definition at line 88 of file callback_net_base.h.

References NLNET::CCallbackNetBase::_BytesReceived, and uint64.

Referenced by NLNET::CUnifiedNetwork::getBytesReceived().

00088 { return _BytesReceived; }

uint64 NLNET::CCallbackNetBase::getBytesSent  )  [inline, inherited]
 

Definition at line 87 of file callback_net_base.h.

References NLNET::CCallbackNetBase::_BytesSent, and uint64.

Referenced by NLNET::CUnifiedNetwork::getBytesSent().

00087 { return _BytesSent; }

uint64 NLNET::CCallbackClient::getReceiveQueueSize  )  [inline, virtual]
 

Implements NLNET::CCallbackNetBase.

Definition at line 85 of file callback_client.h.

References uint64.

00085 { return CBufClient::getReceiveQueueSize(); }

uint32 NLNET::CBufClient::getSendQueueSize  )  const [inline, inherited]
 

Definition at line 135 of file buf_client.h.

References NLNET::CBufClient::_BufSock, NLNET::CBufSock::SendFifo, NLMISC::CBufFIFO::size(), and uint32.

00135 { return _BufSock->SendFifo.size(); }

uint64 NLNET::CCallbackClient::getSendQueueSize  )  [inline, virtual]
 

Implements NLNET::CCallbackNetBase.

Definition at line 86 of file callback_client.h.

References uint64.

00086 { return CBufClient::getSendQueueSize(); }

NLMISC::CStringIdArray& NLNET::CCallbackNetBase::getSIDA  )  [inline, inherited]
 

Use this function to get the String ID Array needed when you want to create a message.

Definition at line 129 of file callback_net_base.h.

References NLNET::CCallbackNetBase::_InputSIDA.

Referenced by NLNET::cbcMessageRecvAllAssociations(), NLNET::cbnbMessageAskAssociations(), NLNET::cbnbMessageRecvAssociations(), NLNET::cbServerAskUniversalTime(), NLNET::cbShardValidation(), NLNET::CLoginClient::connectToShard(), NLNET::CNetDisplayer::doDisplay(), NLNET::CNamingClient::queryServicePort(), NLNET::CNamingClient::registerService(), NLNET::CNamingClient::registerServiceWithSId(), NLNET::CNamingClient::resendRegisteration(), NLNET::CCallbackServer::sendAllMyAssociations(), NLNET::CCallbackNetBase::setOtherSideAssociations(), and NLNET::CNamingClient::unregisterService().

00129 { return _InputSIDA; }

TSockId NLNET::CCallbackClient::getSockId TSockId  hostid = InvalidSockId  )  [virtual]
 

Returns the sockid.

Implements NLNET::CCallbackNetBase.

Definition at line 272 of file callback_client.cpp.

References NLNET::CCallbackNetBase::checkThreadId(), NLNET::CBufClient::id(), nlassert, and NLNET::TSockId.

Referenced by NLNET::CNetManager::addClient(), NLNET::CUnifiedNetwork::addService(), NLNET::CNetManager::createConnection(), and NLNET::CNetManager::update().

00273 {
00274         nlassert (hostid == InvalidSockId);
00275         checkThreadId ();
00276 
00277         return id ();
00278 }

virtual const CInetAddress& NLNET::CCallbackClient::hostAddress TSockId  hostid  )  [inline, virtual]
 

Returns the address of the specified host.

Reimplemented from NLNET::CCallbackNetBase.

Definition at line 71 of file callback_client.h.

References NLNET::CBufClient::remoteAddress(), and NLNET::TSockId.

00071 { return remoteAddress(); }

TSockId NLNET::CBufClient::id  )  const [inline, inherited]
 

Returns the id of the connection.

Definition at line 198 of file buf_client.h.

References NLNET::CBufClient::_BufSock, and NLNET::TSockId.

Referenced by NLNET::CPacsClient::connect(), NLNET::CBufClient::dataAvailable(), and getSockId().

00198 { return _BufSock; /*_RecvTask->sockId();*/ }

void NLNET::CCallbackNetBase::ignoreAllUnknownId bool  b  )  [inline, inherited]
 

If you ignore all unknown id, the net will not ask for other side to know new association. It's used in the naming service for example because the naming client will never answer. In this case, it will always send the message with the full string name (slower)

Definition at line 157 of file callback_net_base.h.

References NLNET::CCallbackNetBase::_InputSIDA, and NLMISC::CStringIdArray::ignoreAllUnknownId().

00158         {
00159                 _InputSIDA.ignoreAllUnknownId (b);
00160         }

bool NLNET::CCallbackNetBase::isAServer  )  const [inline, inherited]
 

Returns true if this is a CCallbackServer.

Definition at line 126 of file callback_net_base.h.

References NLNET::CCallbackNetBase::_IsAServer, and NLNET::CCallbackNetBase::checkThreadId().

00126 { checkThreadId (); return _IsAServer; }

uint32 NLNET::CBufNetBase::maxExpectedBlockSize  )  const [inline, inherited]
 

Returns the max size of the received messages (default: 2^31-1).

Definition at line 135 of file buf_net_base.h.

References NLNET::CBufNetBase::_MaxExpectedBlockSize, and uint32.

Referenced by NLNET::CBufClient::connect(), and NLNET::CBufServer::init().

00136         {
00137                 return _MaxExpectedBlockSize;
00138         }

uint32 NLNET::CBufNetBase::maxSentBlockSize  )  const [inline, inherited]
 

Returns the max size of the sent messages (default: 2^31-1).

Definition at line 141 of file buf_net_base.h.

References NLNET::CBufNetBase::_MaxSentBlockSize, and uint32.

Referenced by NLNET::CBufServer::send(), and NLNET::CBufClient::send().

00142         {
00143                 return _MaxSentBlockSize;
00144         }

uint64 NLNET::CBufClient::newBytesDownloaded  )  [inherited]
 

Returns the number of bytes downloaded since the previous call to this method.

Definition at line 361 of file buf_client.cpp.

References NLNET::CBufClient::_PrevBytesDownloaded, NLNET::CBufClient::bytesDownloaded(), uint64, and NLNET::updateStatCounter().

00362 {
00363         return updateStatCounter( _PrevBytesDownloaded, bytesDownloaded() );
00364 }

uint64 NLNET::CBufClient::newBytesUploaded  )  [inherited]
 

Returns the number of bytes uploaded since the previous call to this method.

Definition at line 370 of file buf_client.cpp.

References NLNET::CBufClient::_PrevBytesUploaded, NLNET::CBufClient::bytesUploaded(), uint64, and NLNET::updateStatCounter().

00371 {
00372         return updateStatCounter( _PrevBytesUploaded, bytesUploaded() );
00373 }

void NLNET::CCallbackNetBase::processOneMessage  )  [protected, inherited]
 

Read a message from the network and process it.

Definition at line 223 of file callback_net_base.cpp.

References NLNET::CCallbackNetBase::_BytesReceived, NLNET::CCallbackNetBase::_CallbackArray, NLNET::CCallbackNetBase::_DefaultCallback, NLNET::CCallbackNetBase::_OutputSIDA, NLNET::CBufSock::asString(), NLNET::CBufSock::AuthorizedCallback, NLNET::CCallbackNetBase::checkThreadId(), NLNET::CCallbackNetBase::disconnect(), NLNET::CMessage::getId(), NLNET::CMessage::getName(), NLNET::CCallbackNetBase::getSockId(), NLNET::CMessage::length(), nldebug, nlwarning, NLNET::CCallbackNetBase::receive(), sint16, NLNET::TMsgCallback, NLNET::CMessage::toString(), NLNET::TSockId, NLMISC::CStringIdArray::TStringId, and NLNET::CMessage::TypeHasAnId.

Referenced by NLNET::CCallbackNetBase::baseUpdate().

00224 {
00225         checkThreadId ();
00226 
00227         // slow down the layer H_AUTO (CCallbackNetBase_processOneMessage);
00228 
00229         CMessage msgin (_OutputSIDA, "", true);
00230         TSockId tsid;
00231         receive (msgin, &tsid);
00232 
00233         _BytesReceived += msgin.length ();
00234         
00235         // now, we have to call the good callback
00236         NLMISC::CStringIdArray::TStringId pos = -1;
00237         if (msgin.TypeHasAnId)
00238         {
00239                 pos = msgin.getId ();
00240         }
00241         else
00242         {
00243                 std::string name = msgin.getName ();
00244                 sint16 i;
00245                 for (i = 0; i < (sint16) _CallbackArray.size (); i++)
00246                 {
00247                         if (name == _CallbackArray[i].Key)
00248                         {
00249                                 pos = i;
00250                                 break;
00251                         }
00252                 }
00253         }
00254 
00255         TMsgCallback    cb = NULL;
00256         if (pos < 0 || pos >= (sint16) _CallbackArray.size ())
00257         {
00258                 if (_DefaultCallback == NULL)
00259                 {
00260                         nlwarning ("LNETL3NB_CB: Callback %s not found in _CallbackArray", msgin.toString().c_str());
00261                 }
00262                 else
00263                 {
00264                         cb = _DefaultCallback;
00265                 }
00266         }
00267         else
00268         {
00269                 cb = _CallbackArray[pos].Callback;
00270         }
00271 
00272         TSockId realid = getSockId (tsid);
00273 
00274         if (!realid->AuthorizedCallback.empty() && msgin.getName() != realid->AuthorizedCallback)
00275         {
00276                 nlwarning ("LNETL3NB_CB: %s try to call the callback %s but only %s is authorized. Disconnect him!", tsid->asString().c_str(), msgin.toString().c_str(), tsid->AuthorizedCallback.c_str());
00277                 disconnect (tsid);
00278         }
00279         else if (cb == NULL)
00280         {
00281                 nlwarning ("LNETL3NB_CB: Callback %s is NULL, can't call it", msgin.toString().c_str());
00282         }
00283         else
00284         {
00285                 nldebug ("LNETL3NB_CB: Calling callback (%s)%s", msgin.getName().c_str(), (cb==_DefaultCallback)?" DEFAULT_CB":"");
00286                 cb(msgin, realid, *this);
00287         }
00288         
00289 /*
00290         if (pos < 0 || pos >= (sint16) _CallbackArray.size ())
00291         {
00292                 if (_DefaultCallback == NULL)
00293                         nlwarning ("LNETL3NB_CB: Callback %s not found in _CallbackArray", msgin.toString().c_str());
00294                 else
00295                 {
00296                         // ...
00297                 }
00298         }
00299         else
00300         {
00301                 TSockId realid = getSockId (tsid);
00302 
00303                 if (!realid->AuthorizedCallback.empty() && msgin.getName() != realid->AuthorizedCallback)
00304                 {
00305                         nlwarning ("LNETL3NB_CB: %s try to call the callback %s but only %s is authorized. Disconnect him!", tsid->asString().c_str(), msgin.toString().c_str(), tsid->AuthorizedCallback.c_str());
00306                         disconnect (tsid);
00307                 }
00308                 else if (_CallbackArray[pos].Callback == NULL)
00309                 {
00310                         nlwarning ("LNETL3NB_CB: Callback %s is NULL, can't call it", msgin.toString().c_str());
00311                 }
00312                 else
00313                 {
00314                         nldebug ("LNETL3NB_CB: Calling callback (%s)", _CallbackArray[pos].Key);
00315                         _CallbackArray[pos].Callback (msgin, realid, *this);
00316                 }
00317         }
00318 */
00319 }

void NLNET::CBufNetBase::pushMessageIntoReceiveQueue const uint8 buffer,
uint32  size
[inline, protected, inherited]
 

Definition at line 183 of file buf_net_base.h.

References NLNET::CBufNetBase::_RecvFifo, buffer, NLNET::CFifoAccessor, NLNET::CBufNetBase::setDataAvailableFlag(), size, uint32, and uint8.

00184         {
00185                 //sint32 mbsize;
00186                 {
00187                         //nldebug( "BNB: Acquiring the receive queue... ");
00188                         CFifoAccessor recvfifo( &_RecvFifo );
00189                         //nldebug( "BNB: Acquired, pushing the received buffer... ");
00190                         recvfifo.value().push( buffer, size );
00191                         //nldebug( "BNB: Pushed, releasing the receive queue..." );
00192                         //mbsize = recvfifo.value().size() / 1048576;
00193                         setDataAvailableFlag( true );
00194                 }
00195                 //nldebug( "BNB: Released." );
00196                 /*if ( mbsize > 1 )
00197                 {
00198                         nlwarning( "The receive queue size exceeds %d MB", mbsize );
00199                 }*/
00200         }

void NLNET::CBufNetBase::pushMessageIntoReceiveQueue const std::vector< uint8 > &  buffer  )  [inline, protected, inherited]
 

Push message into receive queue (mutexed).

Definition at line 164 of file buf_net_base.h.

References NLNET::CBufNetBase::_RecvFifo, buffer, NLNET::CFifoAccessor, and NLNET::CBufNetBase::setDataAvailableFlag().

Referenced by NLNET::CBufSock::advertiseSystemEvent(), and NLNET::CClientReceiveTask::run().

00165         {
00166                 //sint32 mbsize;
00167                 {
00168                         //nldebug( "BNB: Acquiring the receive queue... ");
00169                         CFifoAccessor recvfifo( &_RecvFifo );
00170                         //nldebug( "BNB: Acquired, pushing the received buffer... ");
00171                         recvfifo.value().push( buffer );
00172                         //nldebug( "BNB: Pushed, releasing the receive queue..." );
00173                         //mbsize = recvfifo.value().size() / 1048576;
00174                         setDataAvailableFlag( true );
00175                 }
00176                 //nldebug( "BNB: Released." );
00177                 //if ( mbsize > 1 )
00178                 //{
00179                 //      nlwarning( "The receive queue size exceeds %d MB", mbsize );
00180                 //}
00181         }

void NLNET::CBufClient::receive NLMISC::CMemStream buffer  )  [inherited]
 

Receives next block of data in the specified buffer (resizes the vector) You must call dataAvailable() before every call to receive()

Definition at line 272 of file buf_client.cpp.

References buffer, NLNET::CFifoAccessor, nlassert, nlnettrace, NLNET::CBufNetBase::receiveQueue(), and NLNET::CBufNetBase::setDataAvailableFlag().

00273 {
00274         nlnettrace( "CBufClient::receive" );
00275         //nlassert( dataAvailable() );
00276 
00277         // Extract buffer from the receive queue
00278         {
00279                 CFifoAccessor recvfifo( &receiveQueue() );
00280                 nlassert( ! recvfifo.value().empty() );
00281                 recvfifo.value().front( buffer );
00282                 recvfifo.value().pop();
00283                 setDataAvailableFlag( ! recvfifo.value().empty() );
00284         }
00285 
00286         // Extract event type
00287         nlassert( buffer.buffer()[buffer.size()-1] == CBufNetBase::User );
00288         //commented for optimisation nldebug( "LNETL1: Client read buffer (%d+%d B)", buffer.size(), sizeof(TSockId)+1 );
00289         buffer.resize( buffer.size()-1 );
00290 }

void NLNET::CCallbackClient::receive CMessage buffer,
TSockId hostid = NULL
[private, virtual]
 

On this layer, you can't call directly receive, It s the update() function that receive and call your callaback.

Implements NLNET::CCallbackNetBase.

Definition at line 220 of file callback_client.cpp.

References buffer, NLNET::CCallbackNetBase::checkThreadId(), nlassert, NLMISC_BSWAP32, nlstopex, NLNET::Receiving, NLNET::TSockId, and uint32.

00221 {
00222         checkThreadId ();
00223         nlassert (connected ());
00224         *hostid = InvalidSockId;
00225 
00226 #ifdef USE_MESSAGE_RECORDER
00227         if ( _MR_RecordingState != Replay )
00228         {
00229 #endif
00230                 
00231                 // Receive
00232                 CBufClient::receive (buffer);
00233 
00234                 // debug features, we number all packet to be sure that they are all sent and received
00235                 // \todo remove this debug feature when ok
00236 #ifdef NL_BIG_ENDIAN
00237                 uint32 val = NLMISC_BSWAP32(*(uint32*)buffer.buffer ());
00238 #else
00239                 uint32 val = *(uint32*)buffer.buffer ();
00240 #endif
00241 
00242 //              nldebug ("receive message number %u", val);
00243                 if (ReceiveNextValue != val)
00244                 {
00245                         nlstopex (("LNETL3C: !!!LOST A MESSAGE!!! I received the message number %u but I'm waiting the message number %u (cnx %s), warn lecroart@nevrax.com with the log now please", val, ReceiveNextValue, id()->asString().c_str()));
00246                         // resync the message number
00247                         ReceiveNextValue = val;
00248                 }
00249                 ReceiveNextValue++;
00250 
00251 #ifdef USE_MESSAGE_RECORDER
00252                 if ( _MR_RecordingState == Record )
00253                 {
00254                         // Record received message
00255                         _MR_Recorder.recordNext( _MR_UpdateCounter, Receiving, *hostid, const_cast<CMessage&>(buffer) );
00256                 }
00257         }
00258         else
00259         {
00260                 // Retrieve received message loaded by dataAvailable()
00261                 buffer = _MR_Recorder.ReceivedMessages.front().Message;
00262                 _MR_Recorder.ReceivedMessages.pop();
00263         }
00264 #endif
00265 
00266         buffer.readType ();
00267 }

CSynchronizedFIFO& NLNET::CBufNetBase::receiveQueue  )  [inline, protected, inherited]
 

Access to the receive queue.

Definition at line 154 of file buf_net_base.h.

References NLNET::CBufNetBase::_RecvFifo, and NLNET::CSynchronizedFIFO.

Referenced by NLNET::CBufServer::dataAvailable(), NLNET::CBufClient::dataAvailable(), NLNET::CBufClient::disconnect(), NLNET::CBufServer::receive(), NLNET::CBufClient::receive(), and NLNET::CServerReceiveTask::run().

00154 { return _RecvFifo; }

const CInetAddress& NLNET::CBufClient::remoteAddress  )  const [inline, inherited]
 

Returns the address of the remote host.

Definition at line 169 of file buf_client.h.

References NLNET::CBufClient::_BufSock, NLNET::CSock::remoteAddr(), and NLNET::CBufSock::Sock.

Referenced by hostAddress(), and NLNET::CNamingClient::info().

00169 { return _BufSock->Sock->remoteAddr(); }

void NLNET::CCallbackClient::send const NLMISC::CMemStream buffer  )  [inline, private]
 

These function is public in the base class and put it private here because user cannot use it in layer 2.

Reimplemented from NLNET::CBufClient.

Definition at line 96 of file callback_client.h.

References nlstop.

00096 { nlstop; }

void NLNET::CCallbackClient::send const CMessage buffer,
TSockId  hostid = InvalidSockId,
bool  log = true
[virtual]
 

Sends a message to the remote host (the second parameter isn't used).

Implements NLNET::CCallbackNetBase.

Definition at line 79 of file callback_client.cpp.

References buffer, NLNET::CCallbackNetBase::checkThreadId(), nlassert, NLMISC_BSWAP32, NLNET::Sending, NLNET::TSockId, and uint32.

Referenced by NLNET::CUnifiedNetwork::addService(), NLNET::CLoginClient::connectToShard(), NLNET::CNetDisplayer::doDisplay(), NLNET::CNamingClient::queryServicePort(), NLNET::CNamingClient::registerService(), NLNET::CNamingClient::registerServiceWithSId(), NLNET::CNamingClient::resendRegisteration(), NLNET::CPacsClient::sendMessage(), and NLNET::CNamingClient::unregisterService().

00080 {
00081         nlassert (hostid == InvalidSockId);     // should always be InvalidSockId on client
00082         checkThreadId ();
00083         nlassert (connected ());
00084         nlassert (buffer.length() != 0);
00085         nlassert (buffer.typeIsSet());
00086 
00087         _BytesSent += buffer.length ();
00088 
00089 //      if (log)
00090         {
00092 //              nldebug ("send message number %u", SendNextValue);
00093         }
00094 
00095         // debug features, we number all packet to be sure that they are all sent and received
00096         // \todo remove this debug feature when ok
00097         // fill the number
00098         uint32 *val = (uint32*)buffer.buffer ();
00099 #ifdef NL_BIG_ENDIAN
00100         *val = NLMISC_BSWAP32(SendNextValue);
00101 #else
00102         *val = SendNextValue;
00103 #endif
00104         SendNextValue++;
00105 
00106 
00107 #ifdef USE_MESSAGE_RECORDER
00108         if ( _MR_RecordingState != Replay )
00109         {
00110 #endif
00111 
00112                 // Send
00113                 CBufClient::send (buffer);
00114 
00115 #ifdef USE_MESSAGE_RECORDER
00116                 if ( _MR_RecordingState == Record )
00117                 {
00118                         // Record sent message
00119                         _MR_Recorder.recordNext( _MR_UpdateCounter, Sending, hostid, const_cast<CMessage&>(buffer) );
00120                 }
00121         }
00122         else
00123         {       
00125         }
00126 #endif
00127 }

void NLNET::CCallbackNetBase::sendAllMyAssociations TSockId  to  )  [inherited]
 

Used by client and server class.

Reimplemented in NLNET::CCallbackServer.

void NLNET::CBufNetBase::setDataAvailableFlag bool  da  )  [inline, protected, inherited]
 

Sets _DataAvailable.

Definition at line 203 of file buf_net_base.h.

References NLNET::CBufNetBase::_DataAvailable.

Referenced by NLNET::CBufServer::dataAvailable(), NLNET::CBufClient::dataAvailable(), NLNET::CBufClient::disconnect(), NLNET::CBufNetBase::pushMessageIntoReceiveQueue(), NLNET::CBufServer::receive(), NLNET::CBufClient::receive(), and NLNET::CServerReceiveTask::run().

00203 { _DataAvailable = da; }

void NLNET::CCallbackNetBase::setDefaultCallback TMsgCallback  defaultCallback  )  [inline, inherited]
 

Sets default callback for unknown message types.

Definition at line 110 of file callback_net_base.h.

References NLNET::CCallbackNetBase::_DefaultCallback, and NLNET::TMsgCallback.

Referenced by NLNET::CUnifiedNetwork::addService(), and NLNET::CUnifiedNetwork::init().

00110 { _DefaultCallback = defaultCallback; }

void NLNET::CCallbackClient::setDisconnectionCallback TNetCallback  cb,
void *  arg
[inline]
 

Sets callback for disconnections (or NULL to disable callback).

Reimplemented from NLNET::CCallbackNetBase.

Definition at line 80 of file callback_client.h.

References NLNET::CCallbackNetBase::checkThreadId(), and NLNET::TNetCallback.

Referenced by NLNET::CUnifiedNetwork::addService().

00080 { checkThreadId (); CCallbackNetBase::setDisconnectionCallback (cb, arg); }

void NLNET::CBufNetBase::setMaxExpectedBlockSize sint32  limit  )  [inline, inherited]
 

Sets the max size of the received messages. If receiving a message bigger than the limit, the connection will be dropped.

Default value: 1 MegaByte If you put a negative number as limit, the max size is reset to the default value. Warning: you can call this method only at initialization time, before connecting (for a client) or calling init() (for a server) !

Definition at line 109 of file buf_net_base.h.

References NLNET::CBufNetBase::_MaxExpectedBlockSize, sint32, and uint32.

00110         {
00111                 if ( limit < 0 )
00112                         _MaxExpectedBlockSize = 1048576;
00113                 else
00114                         _MaxExpectedBlockSize = (uint32)limit;
00115         }

void NLNET::CBufNetBase::setMaxSentBlockSize sint32  limit  )  [inline, inherited]
 

Sets the max size of the sent messages. Note: Limiting of sending not implemented, currently

Default value: 1 MegaByte If you put a negative number as limit, the max size is reset to the default value. Warning: you can call this method only at initialization time, before connecting (for a client) or calling init() (for a server) !

Definition at line 126 of file buf_net_base.h.

References NLNET::CBufNetBase::_MaxSentBlockSize, sint32, and uint32.

00127         {
00128                 if ( limit < 0 )
00129                         _MaxSentBlockSize = 1048576;
00130                 else
00131                         _MaxSentBlockSize = (uint32)limit;
00132         }

void NLNET::CCallbackNetBase::setOtherSideAssociations const char **  associationarray,
NLMISC::CStringIdArray::TStringId  arraysize
[inherited]
 

Gives some association of the other side. The goal is, in specific case, we don't want to ask associations to the other side (client is not secure for example). In this case, we can set other side associations by hand using this functions.

Definition at line 451 of file callback_net_base.cpp.

References NLMISC::CStringIdArray::addString(), NLNET::CCallbackNetBase::checkThreadId(), NLNET::CCallbackNetBase::getSIDA(), nldebug, sint, and NLMISC::CStringIdArray::TStringId.

00452 {
00453         checkThreadId ();
00454 
00455         nldebug ("LNETL3NB_ASSOC: setOtherSideAssociations() sets %d association strings", arraysize);
00456 
00457         for (sint i = 0; i < arraysize; i++)
00458         {
00459                 nldebug ("LNETL3NB_ASSOC:  association '%s' -> %d", associationarray[i], i);
00460                 getSIDA().addString (associationarray[i], i);
00461         }
00462 }

void NLNET::CBufClient::setSizeFlushTrigger sint32  size  )  [inline, inherited]
 

Sets the size flush trigger. When the size of the send queue reaches or exceeds this calue, all data in the send queue is automatically sent (-1 to disable this trigger )

Definition at line 152 of file buf_client.h.

References NLNET::CBufClient::_BufSock, NLNET::CBufSock::setSizeFlushTrigger(), sint32, and size.

00152 { _BufSock->setSizeFlushTrigger( size ); }

void NLNET::CBufClient::setTimeFlushTrigger sint32  ms  )  [inline, inherited]
 

Sets the time flush trigger (in millisecond). When this time is elapsed, all data in the send queue is automatically sent (-1 to disable this trigger)

Definition at line 147 of file buf_client.h.

References NLNET::CBufClient::_BufSock, NLNET::CBufSock::setTimeFlushTrigger(), and sint32.

00147 { _BufSock->setTimeFlushTrigger( ms ); }

void NLNET::CBufClient::update  )  [inherited]
 

Update the network (call this method evenly).

Definition at line 296 of file buf_client.cpp.

References NLNET::CBufClient::_BufSock, NLNET::CBufSock::advertiseDisconnection(), NLNET::CSock::connected(), NLNET::CTcpSock::disconnect(), NLNET::CBufSock::Sock, and NLNET::CBufSock::update().

00297 {
00298         //nlnettrace( "CBufClient::update" );
00299 
00300         // Update sending
00301         bool sendingok = _BufSock->update();
00302 
00303         // Disconnection event if disconnected
00304         if ( ! ( _BufSock->Sock->connected() && sendingok ) )
00305         {
00306                 if ( _BufSock->Sock->connected() )
00307                 {
00308                         _BufSock->Sock->disconnect();
00309                 }
00310                 _BufSock->advertiseDisconnection( this, NULL );
00311         }
00312 }

void NLNET::CCallbackClient::update sint32  timeout = 0  )  [virtual]
 

Updates the network (call this method evenly).

Reimplemented from NLNET::CCallbackNetBase.

Definition at line 162 of file callback_client.cpp.

References NLNET::CCallbackNetBase::baseUpdate(), NLNET::CCallbackNetBase::checkThreadId(), H_AUTO, and sint32.

Referenced by NLNET::CLoginClient::connectToShard(), NLNET::CNamingClient::queryServicePort(), NLNET::CNamingClient::registerService(), NLNET::CNamingClient::registerServiceWithSId(), NLNET::CPacsClient::update(), and NLNET::CNamingClient::update().

00163 {
00164 //      nldebug ("L3: Client: update()");
00165 
00166         H_AUTO(L3UpdateClient);
00167 
00168         checkThreadId ();
00169 
00170         baseUpdate (timeout); // first receive
00171 
00172 #ifdef USE_MESSAGE_RECORDER
00173         if ( _MR_RecordingState != Replay )
00174         {
00175 #endif
00176 
00177                 // L1-2 Update (nothing to do in replay mode)
00178                 CBufClient::update (); // then send
00179 
00180 #ifdef USE_MESSAGE_RECORDER
00181         }
00182 #endif
00183         
00184 }


Friends And Related Function Documentation

friend class CClientReceiveTask [friend, inherited]
 

Definition at line 203 of file buf_client.h.

Referenced by NLNET::CBufClient::CBufClient().

friend class NLNET::CBufSock [friend, inherited]
 

Definition at line 148 of file buf_net_base.h.


Field Documentation

CNonBlockingBufSock* NLNET::CBufClient::_BufSock [protected, inherited]
 

Send buffer and connection.

Definition at line 206 of file buf_client.h.

Referenced by NLNET::CBufClient::bytesDownloaded(), NLNET::CBufClient::bytesUploaded(), NLNET::CBufClient::CBufClient(), NLNET::CBufClient::connect(), NLNET::CBufClient::connected(), NLNET::CBufClient::dataAvailable(), NLNET::CBufClient::disconnect(), NLNET::CBufClient::displaySendQueueStat(), NLNET::CBufClient::flush(), NLNET::CBufClient::getSendQueueSize(), NLNET::CBufClient::id(), NLNET::CBufClient::remoteAddress(), NLNET::CBufClient::send(), NLNET::CBufClient::setSizeFlushTrigger(), NLNET::CBufClient::setTimeFlushTrigger(), NLNET::CBufClient::update(), and NLNET::CBufClient::~CBufClient().

uint64 NLNET::CCallbackNetBase::_BytesReceived [protected, inherited]
 

Definition at line 167 of file callback_net_base.h.

Referenced by NLNET::CCallbackNetBase::CCallbackNetBase(), NLNET::CCallbackNetBase::getBytesReceived(), and NLNET::CCallbackNetBase::processOneMessage().

uint64 NLNET::CCallbackNetBase::_BytesSent [protected, inherited]
 

Definition at line 167 of file callback_net_base.h.

Referenced by NLNET::CCallbackNetBase::CCallbackNetBase(), and NLNET::CCallbackNetBase::getBytesSent().

std::vector<TCallbackItem> NLNET::CCallbackNetBase::_CallbackArray [protected, inherited]
 

Definition at line 196 of file callback_net_base.h.

Referenced by NLNET::CCallbackNetBase::addCallbackArray(), and NLNET::CCallbackNetBase::processOneMessage().

TMsgCallback NLNET::CCallbackNetBase::_DefaultCallback [protected, inherited]
 

Definition at line 199 of file callback_net_base.h.

Referenced by NLNET::CCallbackNetBase::processOneMessage(), and NLNET::CCallbackNetBase::setDefaultCallback().

bool NLNET::CCallbackNetBase::_FirstUpdate [protected, inherited]
 

Definition at line 202 of file callback_net_base.h.

Referenced by NLNET::CCallbackNetBase::baseUpdate().

NLMISC::CStringIdArray NLNET::CCallbackNetBase::_InputSIDA [protected, inherited]
 

Definition at line 188 of file callback_net_base.h.

Referenced by NLNET::CCallbackNetBase::baseUpdate(), NLNET::CCallbackNetBase::getSIDA(), and NLNET::CCallbackNetBase::ignoreAllUnknownId().

bool NLNET::CCallbackNetBase::_IsAServer [protected, inherited]
 

Definition at line 201 of file callback_net_base.h.

Referenced by NLNET::CCallbackNetBase::isAServer().

TNetCallback NLNET::CCallbackNetBase::_NewDisconnectionCallback [protected, inherited]
 

Used by client and server class.

Definition at line 170 of file callback_net_base.h.

Referenced by NLNET::CCallbackNetBase::CCallbackNetBase().

bool NLNET::CBufClient::_NoDelay [protected, inherited]
 

True when the Nagle algorithm must be disabled (TCP_NODELAY).

Definition at line 209 of file buf_client.h.

Referenced by NLNET::CBufClient::connect().

NLMISC::CStringIdArray NLNET::CCallbackNetBase::_OutputSIDA [protected, inherited]
 

Definition at line 193 of file callback_net_base.h.

Referenced by NLNET::CCallbackNetBase::addCallbackArray(), NLNET::cbnbMessageAskAssociations(), NLNET::CCallbackNetBase::displayAllMyAssociations(), and NLNET::CCallbackNetBase::processOneMessage().

uint64 NLNET::CBufClient::_PrevBytesDownloaded [protected, inherited]
 

Previous number of bytes downloaded.

Definition at line 212 of file buf_client.h.

Referenced by NLNET::CBufClient::connect(), and NLNET::CBufClient::newBytesDownloaded().

uint64 NLNET::CBufClient::_PrevBytesUploaded [protected, inherited]
 

Previous number of bytes uploaded.

Definition at line 215 of file buf_client.h.

Referenced by NLNET::CBufClient::connect(), and NLNET::CBufClient::newBytesUploaded().

uint NLNET::CCallbackNetBase::_ThreadId [protected, inherited]
 

Todo:
ace: debug feature that we should remove one day nefore releasing the game

Definition at line 232 of file callback_net_base.h.

Referenced by NLNET::CCallbackNetBase::CCallbackNetBase().

uint32 NLNET::CCallbackClient::ReceiveNextValue [private]
 

Definition at line 111 of file callback_client.h.

uint32 NLNET::CCallbackClient::SendNextValue [private]
 

Definition at line 111 of file callback_client.h.


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 13:54:51 2004 for NeL by doxygen 1.3.6