NLNET::CBufNetBase Class Reference

#include <buf_net_base.h>

Inheritance diagram for NLNET::CBufNetBase:

NLNET::CBufClient NLNET::CBufServer NLNET::CCallbackClient NLNET::CCallbackServer

Detailed Description

Layer 1

Base class for CBufClient and CBufServer. The max block sizes for sending and receiving are controlled by setMaxSentBlockSize() and setMaxExpectedBlockSize(). Their default value is the maximum number contained in a sint32, that is 2^31-1 (i.e. 0x7FFFFFFF). The limit for sending is checked only in debug mode.

Author:
Nevrax France
Date:
2001

Definition at line 74 of file buf_net_base.h.

Public Types

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


Public Member Functions

void displayReceiveQueueStat (NLMISC::CLog *log=NLMISC::InfoLog)
uint32 getReceiveQueueSize ()
 Returns the size of the receive queue (mutexed).

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

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

void setMaxExpectedBlockSize (sint32 limit)
void setMaxSentBlockSize (sint32 limit)
virtual ~CBufNetBase ()
 Destructor.


Protected Member Functions

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

 CBufNetBase ()
 Constructor.

volatile bool dataAvailableFlag () const
 Return _DataAvailable.

TNetCallback disconnectionCallback () const
 Returns the disconnection callback.

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.


Private Attributes

volatile bool _DataAvailable
 True if there is data available (avoids locking a mutex).

TNetCallback _DisconnectionCallback
 Callback for disconnection.

void * _DisconnectionCbArg
 Argument of the disconnection callback.

uint32 _MaxExpectedBlockSize
 Max size of received messages (limited by the user).

uint32 _MaxSentBlockSize
 Max size of sent messages (limited by the user).

CSynchronizedFIFO _RecvFifo
 The receive queue, protected by a mutex-like device.


Friends

class NLNET::CBufSock


Member Enumeration Documentation

enum NLNET::CBufNetBase::TEventType
 

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


Constructor & Destructor Documentation

virtual NLNET::CBufNetBase::~CBufNetBase  )  [inline, virtual]
 

Destructor.

Definition at line 82 of file buf_net_base.h.

00082 {};

NLNET::CBufNetBase::CBufNetBase  )  [protected]
 

Constructor.

Definition at line 46 of file buf_net_base.cpp.

00046                          :
00047         _RecvFifo("CBufNetBase::_RecvFifo"),
00048         _DataAvailable( false ),
00049         _DisconnectionCallback( NULL ),
00050         _DisconnectionCbArg( NULL ),
00051         _MaxExpectedBlockSize( 10485760 ), // 10M
00052         _MaxSentBlockSize( 10485760 )
00053 {
00054         // Debug info for mutexes
00055 #ifdef MUTEX_DEBUG
00056         initAcquireTimeMap();
00057 #endif
00058 }


Member Function Documentation

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

Returns the argument of the disconnection callback.

Definition at line 160 of file buf_net_base.h.

References _DisconnectionCbArg.

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

00160 { return _DisconnectionCbArg; }

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

Return _DataAvailable.

Definition at line 206 of file buf_net_base.h.

References _DataAvailable.

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

00206 { return _DataAvailable; }

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

Returns the disconnection callback.

Definition at line 157 of file buf_net_base.h.

References _DisconnectionCallback, and NLNET::TNetCallback.

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

00157 { return _DisconnectionCallback; }

void NLNET::CBufNetBase::displayReceiveQueueStat NLMISC::CLog log = NLMISC::InfoLog  )  [inline]
 

Reimplemented in NLNET::CCallbackClient, and NLNET::CCallbackServer.

Definition at line 94 of file buf_net_base.h.

References _RecvFifo, and NLNET::CFifoAccessor.

00095         {
00096                 CFifoAccessor syncfifo( &_RecvFifo );
00097                 syncfifo.value().displayStats(log);
00098         }

uint32 NLNET::CBufNetBase::getReceiveQueueSize  )  [inline]
 

Returns the size of the receive queue (mutexed).

Reimplemented in NLNET::CCallbackClient, and NLNET::CCallbackServer.

Definition at line 88 of file buf_net_base.h.

References _RecvFifo, NLNET::CFifoAccessor, and uint32.

00089         {
00090                 CFifoAccessor syncfifo( &_RecvFifo );
00091                 return syncfifo.value().size();
00092         }

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

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

Definition at line 135 of file buf_net_base.h.

References _MaxExpectedBlockSize, and uint32.

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

00136         {
00137                 return _MaxExpectedBlockSize;
00138         }

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

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

Definition at line 141 of file buf_net_base.h.

References _MaxSentBlockSize, and uint32.

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

00142         {
00143                 return _MaxSentBlockSize;
00144         }

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

Definition at line 183 of file buf_net_base.h.

References _RecvFifo, buffer, NLNET::CFifoAccessor, 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]
 

Push message into receive queue (mutexed).

Definition at line 164 of file buf_net_base.h.

References _RecvFifo, buffer, NLNET::CFifoAccessor, and 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         }

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

Access to the receive queue.

Definition at line 154 of file buf_net_base.h.

References _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; }

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

Sets _DataAvailable.

Definition at line 203 of file buf_net_base.h.

References _DataAvailable.

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

00203 { _DataAvailable = da; }

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

Sets callback for detecting a disconnection (or NULL to disable callback).

Reimplemented in NLNET::CCallbackClient, and NLNET::CCallbackServer.

Definition at line 85 of file buf_net_base.h.

References _DisconnectionCallback, _DisconnectionCbArg, and NLNET::TNetCallback.

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

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 _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]
 

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 _MaxSentBlockSize, sint32, and uint32.

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


Friends And Related Function Documentation

friend class NLNET::CBufSock [friend]
 

Definition at line 148 of file buf_net_base.h.


Field Documentation

volatile bool NLNET::CBufNetBase::_DataAvailable [private]
 

True if there is data available (avoids locking a mutex).

Definition at line 214 of file buf_net_base.h.

Referenced by dataAvailableFlag(), and setDataAvailableFlag().

TNetCallback NLNET::CBufNetBase::_DisconnectionCallback [private]
 

Callback for disconnection.

Definition at line 217 of file buf_net_base.h.

Referenced by disconnectionCallback(), and setDisconnectionCallback().

void* NLNET::CBufNetBase::_DisconnectionCbArg [private]
 

Argument of the disconnection callback.

Definition at line 220 of file buf_net_base.h.

Referenced by argOfDisconnectionCallback(), and setDisconnectionCallback().

uint32 NLNET::CBufNetBase::_MaxExpectedBlockSize [private]
 

Max size of received messages (limited by the user).

Definition at line 223 of file buf_net_base.h.

Referenced by maxExpectedBlockSize(), and setMaxExpectedBlockSize().

uint32 NLNET::CBufNetBase::_MaxSentBlockSize [private]
 

Max size of sent messages (limited by the user).

Definition at line 226 of file buf_net_base.h.

Referenced by maxSentBlockSize(), and setMaxSentBlockSize().

CSynchronizedFIFO NLNET::CBufNetBase::_RecvFifo [private]
 

The receive queue, protected by a mutex-like device.

Definition at line 211 of file buf_net_base.h.

Referenced by displayReceiveQueueStat(), getReceiveQueueSize(), pushMessageIntoReceiveQueue(), and receiveQueue().


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