#include <buf_client.h>
Inheritance diagram for NLNET::CClientReceiveTask:
Definition at line 45 of file buf_client.h.
Public Member Functions | |
CNonBlockingBufSock * | bufSock () |
Returns a pointer to the bufsock object. | |
CClientReceiveTask (CBufClient *client, CNonBlockingBufSock *bufsock) | |
Constructor (increments the reference to the object pointed to by the smart pointer sockid). | |
virtual void | getName (std::string &result) const |
virtual void | run () |
Run. | |
TSockId | sockId () |
Returns the socket identifier. | |
Data Fields | |
uint32 | NbLoop |
Private Attributes | |
CBufClient * | _Client |
CNonBlockingBufSock * | _NBBufSock |
|
Constructor (increments the reference to the object pointed to by the smart pointer sockid).
Definition at line 50 of file buf_client.h. References _Client, _NBBufSock, and NbLoop.
00050 : NbLoop(0), _Client(client), _NBBufSock(bufsock) {} // CHANGED: non-blocking client connection |
|
Returns a pointer to the bufsock object.
Definition at line 56 of file buf_client.h. References _NBBufSock.
00056 { return _NBBufSock; } // CHANGED: non-blocking client connection (previously, returned _SockId->Sock) |
|
Reimplemented in NL3D::CAsyncFileManager3D::CMeshLoad, NL3D::CAsyncFileManager3D::CIGLoad, NL3D::CAsyncFileManager3D::CIGLoadUser, NL3D::CAsyncFileManager3D::CTextureLoad, NL3D::CZoneLoadingTask, NLPACS::CGlobalRetriever::CLrLoader, NLMISC::CAsyncFileManager::CFileLoad, NLMISC::CAsyncFileManager::CMultipleFileLoad, and NLMISC::CAsyncFileManager::CSignal. Definition at line 74 of file thread.h. Referenced by NLMISC::CTaskManager::run().
00075 {
00076 result = "NoName";
00077 }
|
|
Run.
Implements NLMISC::IRunnable. Definition at line 437 of file buf_client.cpp. References _Client, _NBBufSock, NLNET::CSock::dataAvailable(), NLNET::CTcpSock::disconnect(), NLNET::CNonBlockingBufSock::fillEventTypeOnly(), NLNET::NbClientReceiveTask, NbLoop, NLNET::NbNetworkTask, nldebug, nlnettrace, NLNET::CBufNetBase::pushMessageIntoReceiveQueue(), NLNET::CNonBlockingBufSock::receivedBuffer(), NLNET::CNonBlockingBufSock::receivePart(), NLNET::CSock::setTimeOutValue(), NLNET::CBufSock::Sock, and sockId().
00438 { 00439 NbClientReceiveTask++; 00440 NbNetworkTask++; 00441 nlnettrace( "CClientReceiveTask::run" ); 00442 00443 _NBBufSock->Sock->setTimeOutValue( 60, 0 ); 00444 00445 bool connected = true; 00446 while ( connected ) // does not call _Sock->connected() to avoid mutex (not needed for client) 00447 { 00448 try 00449 { 00450 // ADDED: non-blocking client connection 00451 00452 // Wait until some data are received (sleepin' select inside) 00453 while ( ! _NBBufSock->Sock->dataAvailable() ); 00454 00455 // Process the data received 00456 if ( _NBBufSock->receivePart( 1 ) ) // 1 for the event type 00457 { 00458 //commented out for optimisation: nldebug( "LNETL1: Client %s received buffer (%u bytes)", _SockId->asString().c_str(), buffer.size()/*, stringFromVector(buffer).c_str()*/ ); 00459 // Add event type 00460 _NBBufSock->fillEventTypeOnly(); 00461 00462 // Push message into receive queue 00463 _Client->pushMessageIntoReceiveQueue( _NBBufSock->receivedBuffer() ); 00464 } 00465 00466 NbLoop++; 00467 00468 /* // OLD: blocking client connection 00469 // Receive message length (in blocking mode) 00470 TBlockSize blocklen; 00471 uint32 lenoflen = sizeof(blocklen); 00472 sock()->receive( (uint8*)&blocklen, lenoflen ); 00473 uint32 len = ntohl( blocklen ); 00474 00475 if ( len != 0 ) 00476 { 00477 // Test size limit 00478 if ( len > _Client->maxExpectedBlockSize() ) 00479 { 00480 nlwarning( "LNETL1: Socket %s received length exceeding max expected, in block header... Disconnecting", _SockId->asString().c_str() ); 00481 throw ESocket( "Received length exceeding max expected", false ); 00482 } 00483 00484 // Receive message payload (in blocking mode) 00485 CObjectVector<uint8> buffer; 00486 buffer.resize(len+1); 00487 00488 sock()->receive( buffer.getPtr(), len ); 00489 00490 //commented out for optimisation: nldebug( "LNETL1: Client %s received buffer (%u bytes)", _SockId->asString().c_str(), buffer.size() ); 00491 // Add event type 00492 buffer[len] = CBufNetBase::User; 00493 00494 // Push message into receive queue 00495 _Client->pushMessageIntoReceiveQueue( buffer.getPtr(), buffer.size() ); 00496 } 00497 else 00498 { 00499 nlwarning( "LNETL1: Socket %s received null length in block header", _SockId->asString().c_str() ); 00500 } 00501 */ 00502 } 00503 catch ( ESocketConnectionClosed& ) 00504 { 00505 nldebug( "LNETL1: Client connection %s closed", sockId()->asString().c_str() ); 00506 // The socket went to _Connected=false when throwing the exception 00507 connected = false; 00508 } 00509 catch ( ESocket& ) 00510 { 00511 nldebug( "LNETL1: Client connection %s broken", sockId()->asString().c_str() ); 00512 sockId()->Sock->disconnect(); 00513 connected = false; 00514 } 00515 } 00516 00517 nlnettrace( "Exiting CClientReceiveTask::run()" ); 00518 NbClientReceiveTask--; 00519 NbNetworkTask--; 00520 } |
|
Returns the socket identifier.
Definition at line 59 of file buf_client.h. References _NBBufSock, and NLNET::TSockId. Referenced by run().
00059 { return (TSockId)_NBBufSock; } |
|
Definition at line 65 of file buf_client.h. Referenced by CClientReceiveTask(), and run(). |
|
Definition at line 67 of file buf_client.h. Referenced by bufSock(), CClientReceiveTask(), run(), and sockId(). |
|
Definition at line 61 of file buf_client.h. Referenced by CClientReceiveTask(), NLNET::CBufClient::displayThreadStat(), and run(). |