From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- docs/doxygen/nel/a02295.html | 2041 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2041 insertions(+) create mode 100644 docs/doxygen/nel/a02295.html (limited to 'docs/doxygen/nel/a02295.html') diff --git a/docs/doxygen/nel/a02295.html b/docs/doxygen/nel/a02295.html new file mode 100644 index 00000000..b8adaafc --- /dev/null +++ b/docs/doxygen/nel/a02295.html @@ -0,0 +1,2041 @@ + + +NeL: NLNET::CBufClient class Reference + + + +
+

NLNET::CBufClient Class Reference

#include <buf_client.h> +

+

Inheritance diagram for NLNET::CBufClient: +

+ +NLNET::CBufNetBase +NLNET::CCallbackClient + +

Detailed Description

+Client class for layer 1

+Active connection with packet scheme and buffering. The provided buffers are sent raw (no endianness conversion). By default, the size time trigger is disabled, the time trigger is set to 20 ms.

+Where do the methods take place: send() -> send buffer -> update(), flush(), bytesUploaded(), newBytesUploaded()

+receive(), <- receive buffer <- receive thread, dataAvailable(), bytesDownloaded(), newBytesDownloaded() disconnection callback

+

Author:
Olivier Cado

+Nevrax France

+
Date:
2001
+ +

+ +

+Definition at line 93 of file buf_client.h. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Types

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


Public Member Functions

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.

 CBufClient (bool nodelay=true, bool replaymode=false)
 Constructor. Set nodelay to true to disable the Nagle buffering algorithm (see CTcpSock documentation).

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

bool connected () const
bool dataAvailable ()
void disconnect (bool quick=false)
void displayReceiveQueueStat (NLMISC::CLog *log=NLMISC::InfoLog)
void displaySendQueueStat (NLMISC::CLog *log=NLMISC::InfoLog)
void displayThreadStat (NLMISC::CLog *log)
bool flush ()
uint32 getReceiveQueueSize ()
 Returns the size of the receive queue (mutexed).

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

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 NLMISC::CMemStream &buffer)
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)
void setSizeFlushTrigger (sint32 size)
void setTimeFlushTrigger (sint32 ms)
void update ()
 Update the network (call this method evenly).

virtual ~CBufClient ()
 Destructor.


Protected Member Functions

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

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.


Protected Attributes

CNonBlockingBufSock_BufSock
 Send buffer and connection.

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

uint64 _PrevBytesDownloaded
 Previous number of bytes downloaded.

uint64 _PrevBytesUploaded
 Previous number of bytes uploaded.


Private Attributes

CClientReceiveTask_RecvTask
 Receive task.

NLMISC::IThread_RecvThread
 Receive thread.


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


Constructor & Destructor Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
NLNET::CBufClient::CBufClient bool  nodelay = true,
bool  replaymode = false
+
+ + + + + +
+   + + +

+Constructor. Set nodelay to true to disable the Nagle buffering algorithm (see CTcpSock documentation). +

+ +

+Definition at line 57 of file buf_client.cpp. +

+References _BufSock, _RecvTask, CClientReceiveTask, and nlnettrace. +

+

00057                                                       :
+00058         CBufNetBase(),
+00059         _NoDelay( nodelay ),
+00060         _PrevBytesDownloaded( 0 ),
+00061         _PrevBytesUploaded( 0 ),
+00062         _RecvTask( NULL ),
+00063         _RecvThread( NULL )
+00064         /*_PrevBytesReceived( 0 ),
+00065         _PrevBytesSent( 0 )*/
+00066 {
+00067         nlnettrace( "CBufClient::CBufClient" ); // don't define a global object
+00068 
+00069         if ( replaymode )
+00070         {
+00071                 _BufSock = new CNonBlockingBufSock( new CDummyTcpSock() ); // CHANGED: non-blocking client connection
+00072         }
+00073         else
+00074         {
+00075                 _BufSock = new CNonBlockingBufSock(); // CHANGED: non-blocking client connection
+00076                 _RecvTask = new CClientReceiveTask( this, _BufSock );
+00077         }
+00078 }
+
+
+

+ + + + +
+ + + + + + + + + +
NLNET::CBufClient::~CBufClient  )  [virtual]
+
+ + + + + +
+   + + +

+Destructor. +

+ +

+Definition at line 397 of file buf_client.cpp. +

+References _BufSock, _RecvTask, _RecvThread, NLNET::CSock::connected(), NLNET::CBufSock::connectedState(), disconnect(), nlassert, nldebug, nlnettrace, NLNET::CBufSock::Sock, and NLMISC::IThread::wait(). +

+

00398 {
+00399         nlnettrace( "CBufClient::~CBufClient" );
+00400 
+00401         // Disconnect if not done
+00402         if ( _BufSock->Sock->connected() )
+00403         {
+00404                 nlassert( _BufSock->connectedState() );
+00405 
+00406                 disconnect( true );
+00407         }
+00408 
+00409         // Clean thread termination
+00410         if ( _RecvThread != NULL )
+00411         {
+00412                 nldebug( "LNETL1: Waiting for the end of the receive thread..." );
+00413                 _RecvThread->wait();
+00414         }
+00415 
+00416         if ( _RecvTask != NULL )
+00417                 delete _RecvTask;
+00418 
+00419         if ( _RecvThread != NULL )
+00420                 delete _RecvThread;
+00421 
+00422         if ( _BufSock != NULL )
+00423                 delete _BufSock;
+00424 
+00425         nlnettrace( "Exiting CBufClient::~CBufClient" );
+00426 }
+
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + +
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 dataAvailable(). +

+

00160 { return _DisconnectionCbArg; }
+
+

+ + + + +
+ + + + + + + + + +
uint64 NLNET::CBufClient::bytesDownloaded  )  const [inline]
+
+ + + + + +
+   + + +

+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 _BufSock, NLNET::CSock::bytesReceived(), NLNET::CBufSock::Sock, and uint64. +

+Referenced by newBytesDownloaded(). +

+

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

+ + + + +
+ + + + + + + + + +
uint64 NLNET::CBufClient::bytesUploaded  )  const [inline]
+
+ + + + + +
+   + + +

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

+ +

+Definition at line 175 of file buf_client.h. +

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

+Referenced by newBytesUploaded(). +

+

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

+ + + + +
+ + + + + + + + + + +
void NLNET::CBufClient::connect const CInetAddress addr  ) 
+
+ + + + + +
+   + + +

+Connects to the specified host. +

+ +

+Reimplemented in NLNET::CCallbackClient. +

+Definition at line 85 of file buf_client.cpp. +

+References _BufSock, _NoDelay, _PrevBytesDownloaded, _PrevBytesUploaded, _RecvTask, _RecvThread, addr, NLNET::CBufSock::connect(), NLNET::CSock::connected(), NLNET::CBufNetBase::maxExpectedBlockSize(), nlassert, nlnettrace, NLNET::CNonBlockingBufSock::setMaxExpectedBlockSize(), NLNET::CNonBlockingBufSock::setNonBlocking(), NLNET::CBufSock::Sock, and NLMISC::IThread::start(). +

+

00086 {
+00087         nlnettrace( "CBufClient::connect" );
+00088         nlassert( ! _BufSock->Sock->connected() );
+00089         _BufSock->setMaxExpectedBlockSize( maxExpectedBlockSize() );
+00090         _BufSock->connect( addr, _NoDelay, true );
+00091         _BufSock->setNonBlocking(); // ADDED: non-blocking client connection
+00092         _PrevBytesDownloaded = 0;
+00093         _PrevBytesUploaded = 0;
+00094         /*_PrevBytesReceived = 0;
+00095         _PrevBytesSent = 0;*/
+00096 
+00097         // Allow reconnection
+00098         if ( _RecvThread != NULL )
+00099         {
+00100                 delete _RecvThread;
+00101         }
+00102 
+00103         _RecvThread = IThread::create( _RecvTask );
+00104         _RecvThread->start();
+00105 }
+
+

+ + + + +
+ + + + + + + + + +
bool NLNET::CBufClient::connected  )  const [inline]
+
+ + + + + +
+   + + +

+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 in NLNET::CCallbackClient. +

+Definition at line 166 of file buf_client.h. +

+References _BufSock, and NLNET::CBufSock::connectedState(). +

+

00166 { return _BufSock->connectedState(); } 
+
+

+ + + + +
+ + + + + + + + + +
bool NLNET::CBufClient::dataAvailable  ) 
+
+ + + + + +
+   + + +

+Checks if there is some data to receive. Returns false if the receive queue is empty. This is where the connection/disconnection callbacks can be called +

+Reimplemented in NLNET::CCallbackClient. +

+Definition at line 140 of file buf_client.cpp. +

+References _BufSock, NLNET::CBufNetBase::argOfDisconnectionCallback(), buffer, NLNET::CFifoAccessor, NLNET::CBufNetBase::dataAvailableFlag(), NLNET::CBufNetBase::disconnectionCallback(), id(), nldebug, nlerror, nlinfo, NLNET::CBufNetBase::receiveQueue(), NLNET::CBufSock::setConnectedState(), NLNET::CBufNetBase::setDataAvailableFlag(), NLMISC::stringFromVector(), uint16, and uint8. +

+

00141 {
+00142         // slow down the layer H_AUTO (CBufClient_dataAvailable);
+00143         {
+00144                 /* If no data available, enter the 'while' loop and return false (1 volatile test)
+00145                  * If there are user data available, enter the 'while' and return true immediately (1 volatile test + 1 short locking)
+00146                  * If there is a disconnection event (rare), call the callback and loop
+00147                  */
+00148                 while ( dataAvailableFlag() )
+00149                 {
+00150                         // Because _DataAvailable is true, the receive queue is not empty at this point
+00151                         uint8 val;
+00152                         {
+00153                                 CFifoAccessor recvfifo( &receiveQueue() );
+00154                                 val = recvfifo.value().frontLast ();
+00155                         }
+00156 
+00157                         // Test if it the next block is a system event
+00158                         switch ( val )
+00159                         {
+00160                                 
+00161                         // Normal message available
+00162                         case CBufNetBase::User:
+00163                                 return true; // return immediatly, do not extract the message
+00164 
+00165                         // Process disconnection event
+00166                         case CBufNetBase::Disconnection:
+00167 
+00168                                 nldebug( "LNETL1: Disconnection event" );
+00169                                 _BufSock->setConnectedState( false );
+00170 
+00171                                 // Call callback if needed
+00172                                 if ( disconnectionCallback() != NULL )
+00173                                 {
+00174                                         disconnectionCallback()( id(), argOfDisconnectionCallback() );
+00175                                 }
+00176 
+00177                                 // Unlike the server version, we do not delete the CBufSock object here,
+00178                                 // it will be done in the destructor of CBufClient
+00179                                 break;
+00180 
+00181                         default: // should not occur
+00182                                 {
+00183                                         CFifoAccessor recvfifo( &receiveQueue() );
+00184                                         vector<uint8> buffer;
+00185                                         recvfifo.value().front (buffer);
+00186                                         nlinfo( "LNETL1: Invalid block type: %hu (should be = %hu)", (uint16)(buffer[buffer.size()-1]), (uint16)val );
+00187                                         nlinfo( "LNETL1: Buffer (%d B): [%s]", buffer.size(), stringFromVector(buffer).c_str() );
+00188                                         nlinfo( "LNETL1: Receive queue:" );
+00189                                         recvfifo.value().display();
+00190                                         nlerror( "LNETL1: Invalid system event type in client receive queue" );
+00191                                 }
+00192                         }
+00193                         // Extract system event
+00194                         {
+00195                                 CFifoAccessor recvfifo( &receiveQueue() );
+00196                                 recvfifo.value().pop();
+00197                                 setDataAvailableFlag( ! recvfifo.value().empty() );
+00198                         }
+00199 
+00200                 }
+00201                 // _DataAvailable is false here
+00202                 return false;
+00203         }
+00204 }
+
+

+ + + + +
+ + + + + + + + + +
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 dataAvailable(). +

+

00206 { return _DataAvailable; }
+
+

+ + + + +
+ + + + + + + + + + +
void NLNET::CBufClient::disconnect bool  quick = false  ) 
+
+ + + + + +
+   + + +

+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 _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 ~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 }
+
+

+ + + + +
+ + + + + + + + + +
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 dataAvailable(). +

+

00157 { return _DisconnectionCallback; }
+
+

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

+ +

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

+Definition at line 94 of file buf_net_base.h. +

+References NLNET::CBufNetBase::_RecvFifo, and NLNET::CFifoAccessor. +

+

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

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

+ +

+Definition at line 137 of file buf_client.h. +

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

+

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

+ + + + +
+ + + + + + + + + + +
void NLNET::CBufClient::displayThreadStat NLMISC::CLog log  ) 
+
+ + + + + +
+   + + +

+ +

+Reimplemented in NLNET::CCallbackClient. +

+Definition at line 112 of file buf_client.cpp. +

+References _RecvTask, NLMISC::CLog::displayNL(), and NLNET::CClientReceiveTask::NbLoop. +

+

00113 {
+00114         log->displayNL ("client thread %p nbloop %d", _RecvTask, _RecvTask->NbLoop);
+00115 }
+
+

+ + + + +
+ + + + + + + + + +
bool NLNET::CBufClient::flush  )  [inline]
+
+ + + + + +
+   + + +

+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 _BufSock, and NLNET::CBufSock::flush(). +

+

00158 { return _BufSock->flush(); }
+
+

+ + + + +
+ + + + + + + + + +
uint32 NLNET::CBufNetBase::getReceiveQueueSize  )  [inline, inherited]
+
+ + + + + +
+   + + +

+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 NLNET::CBufNetBase::_RecvFifo, NLNET::CFifoAccessor, and uint32. +

+

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

+ + + + +
+ + + + + + + + + +
uint32 NLNET::CBufClient::getSendQueueSize  )  const [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 135 of file buf_client.h. +

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

+

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

+ + + + +
+ + + + + + + + + +
TSockId NLNET::CBufClient::id  )  const [inline]
+
+ + + + + +
+   + + +

+Returns the id of the connection. +

+ +

+Definition at line 198 of file buf_client.h. +

+References _BufSock, and NLNET::TSockId. +

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

+

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

+ + + + +
+ + + + + + + + + +
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 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 send(). +

+

00142         {
+00143                 return _MaxSentBlockSize;
+00144         }
+
+

+ + + + +
+ + + + + + + + + +
uint64 NLNET::CBufClient::newBytesDownloaded  ) 
+
+ + + + + +
+   + + +

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

+ +

+Definition at line 361 of file buf_client.cpp. +

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

+

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

+ + + + +
+ + + + + + + + + +
uint64 NLNET::CBufClient::newBytesUploaded  ) 
+
+ + + + + +
+   + + +

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

+ +

+Definition at line 370 of file buf_client.cpp. +

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

+

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

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

+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 }
+
+

+ + + + +
+ + + + + + + + + +
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(), dataAvailable(), disconnect(), NLNET::CBufServer::receive(), receive(), and NLNET::CServerReceiveTask::run(). +

+

00154 { return _RecvFifo; }
+
+

+ + + + +
+ + + + + + + + + +
const CInetAddress& NLNET::CBufClient::remoteAddress  )  const [inline]
+
+ + + + + +
+   + + +

+Returns the address of the remote host. +

+ +

+Definition at line 169 of file buf_client.h. +

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

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

+

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

+ + + + +
+ + + + + + + + + + +
void NLNET::CBufClient::send const NLMISC::CMemStream buffer  ) 
+
+ + + + + +
+   + + +

+Sends a message to the remote host (in fact the message is buffered into the send queue) +

+Reimplemented in NLNET::CCallbackClient. +

+Definition at line 121 of file buf_client.cpp. +

+References _BufSock, NLNET::CBufSock::advertiseDisconnection(), buffer, NLNET::CBufNetBase::maxSentBlockSize(), nlassert, nlnettrace, and NLNET::CBufSock::pushBuffer(). +

+

00122 {
+00123         nlnettrace( "CBufClient::send" );
+00124         nlassert( buffer.length() > 0 );
+00125         nlassert( buffer.length() <= maxSentBlockSize() );
+00126 
+00127         // slow down the layer H_AUTO (CBufServer_send);
+00128 
+00129         if ( ! _BufSock->pushBuffer( buffer ) )
+00130         {
+00131                 // Disconnection event if disconnected
+00132                 _BufSock->advertiseDisconnection( this, NULL );
+00133         }
+00134 }
+
+

+ + + + +
+ + + + + + + + + + +
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(), dataAvailable(), disconnect(), NLNET::CBufNetBase::pushMessageIntoReceiveQueue(), NLNET::CBufServer::receive(), receive(), and NLNET::CServerReceiveTask::run(). +

+

00203 { _DataAvailable = da; }
+
+

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

+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 NLNET::CBufNetBase::_DisconnectionCallback, NLNET::CBufNetBase::_DisconnectionCbArg, and NLNET::TNetCallback. +

+

00085 { _DisconnectionCallback = cb; _DisconnectionCbArg = 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::CBufClient::setSizeFlushTrigger sint32  size  )  [inline]
+
+ + + + + +
+   + + +

+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 _BufSock, NLNET::CBufSock::setSizeFlushTrigger(), sint32, and size. +

+

00152 { _BufSock->setSizeFlushTrigger( size ); }
+
+

+ + + + +
+ + + + + + + + + + +
void NLNET::CBufClient::setTimeFlushTrigger sint32  ms  )  [inline]
+
+ + + + + +
+   + + +

+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 _BufSock, NLNET::CBufSock::setTimeFlushTrigger(), and sint32. +

+

00147 { _BufSock->setTimeFlushTrigger( ms ); }
+
+

+ + + + +
+ + + + + + + + + +
void NLNET::CBufClient::update  ) 
+
+ + + + + +
+   + + +

+Update the network (call this method evenly). +

+ +

+Definition at line 296 of file buf_client.cpp. +

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


Friends And Related Function Documentation

+

+ + + + +
+ + +
friend class CClientReceiveTask [friend] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 203 of file buf_client.h. +

+Referenced by CBufClient().

+

+ + + + +
+ + +
friend class NLNET::CBufSock [friend, inherited] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 148 of file buf_net_base.h.

+


Field Documentation

+

+ + + + +
+ + +
CNonBlockingBufSock* NLNET::CBufClient::_BufSock [protected] +
+
+ + + + + +
+   + + +

+Send buffer and connection. +

+ +

+Definition at line 206 of file buf_client.h. +

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

+

+ + + + +
+ + +
bool NLNET::CBufClient::_NoDelay [protected] +
+
+ + + + + +
+   + + +

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

+ +

+Definition at line 209 of file buf_client.h. +

+Referenced by connect().

+

+ + + + +
+ + +
uint64 NLNET::CBufClient::_PrevBytesDownloaded [protected] +
+
+ + + + + +
+   + + +

+Previous number of bytes downloaded. +

+ +

+Definition at line 212 of file buf_client.h. +

+Referenced by connect(), and newBytesDownloaded().

+

+ + + + +
+ + +
uint64 NLNET::CBufClient::_PrevBytesUploaded [protected] +
+
+ + + + + +
+   + + +

+Previous number of bytes uploaded. +

+ +

+Definition at line 215 of file buf_client.h. +

+Referenced by connect(), and newBytesUploaded().

+

+ + + + +
+ + +
CClientReceiveTask* NLNET::CBufClient::_RecvTask [private] +
+
+ + + + + +
+   + + +

+Receive task. +

+ +

+Definition at line 228 of file buf_client.h. +

+Referenced by CBufClient(), connect(), displayThreadStat(), and ~CBufClient().

+

+ + + + +
+ + +
NLMISC::IThread* NLNET::CBufClient::_RecvThread [private] +
+
+ + + + + +
+   + + +

+Receive thread. +

+ +

+Definition at line 231 of file buf_client.h. +

+Referenced by connect(), and ~CBufClient().

+


The documentation for this class was generated from the following files: +
Generated on Tue Mar 16 13:52:09 2004 for NeL by + +doxygen +1.3.6
+ + -- cgit v1.2.1