#include <dummy_tcp_sock.h>
Inheritance diagram for NLNET::CDummyTcpSock:
Nevrax France
Definition at line 42 of file dummy_tcp_sock.h.
Receiving data | |
bool | dataAvailable () |
Checks if there is some data to receive, waiting (blocking) at most for the time out value. | |
CSock::TSockResult | receive (uint8 *buffer, uint32 &len, bool throw_exception=true) |
Public Types | |
enum | TSockResult { Ok, WouldBlock, ConnectionClosed, Error } |
Public Member Functions | |
uint64 | bytesReceived () const |
Returns the number of bytes received since the latest connection. | |
uint64 | bytesSent () const |
Returns the number of bytes sent since the latest connection. | |
CDummyTcpSock (bool logging=true) | |
virtual void | close () |
virtual void | connect (const CInetAddress &addr) |
virtual void | disconnect () |
Active disconnection (shutdown) (mutexed). connected() becomes false. | |
sint32 | getSendBufferSize () |
Gets the send buffer size. | |
virtual void | setNoDelay (bool value) |
void | setSendBufferSize (sint32 size) |
Sets the send buffer size. | |
void | setTimeOutValue (long sec, long ms) |
Change the time out value used in getDataAvailable(), which is 0 by default. | |
Static Public Member Functions | |
std::string | errorString (uint errorcode) |
Returns a string explaining the network error (see getLastError()). | |
uint | getLastError () |
bool | initialized () |
Returns true if the network engine is initialized. | |
void | initNetwork () |
Initialize the network engine, if it is not already done. | |
void | releaseNetwork () |
Releases the network engine. | |
Protected Member Functions | |
void | createSocket (int type, int protocol) |
Creates the socket and get a valid descriptor. | |
void | setLocalAddress () |
Sets the local address. | |
Protected Attributes | |
uint64 | _BytesReceived |
Number of bytes received on this socket. | |
uint64 | _BytesSent |
Number of bytes sent on this socket. | |
volatile bool | _Connected |
True after calling connect(). | |
CInetAddress | _LocalAddr |
Address of local host (valid if connected). | |
bool | _Logging |
If false, do not log any information. | |
bool | _NonBlocking |
If true, the socket is in nonblocking mode. | |
CInetAddress | _RemoteAddr |
Address of the remote host (valid if connected). | |
SOCKET | _Sock |
Socket descriptor. | |
long | _TimeoutMs |
Secondary time out value (ms) for select in dataAvailable(). | |
long | _TimeoutS |
Main time out value (sec) for select in dataAvailable(). |
|
Definition at line 125 of file sock.h.
00125 { Ok, WouldBlock, ConnectionClosed, Error }; |
|
Definition at line 47 of file dummy_tcp_sock.h.
00047 : CTcpSock(logging) {} |
|
Returns the number of bytes received since the latest connection.
Definition at line 249 of file sock.h. References uint64. Referenced by NLNET::CBufClient::bytesDownloaded().
00249 { return _BytesReceived; } |
|
Returns the number of bytes sent since the latest connection.
Definition at line 252 of file sock.h. References uint64. Referenced by NLNET::CBufClient::bytesUploaded().
00252 { return _BytesSent; } |
|
Closes the socket (without shutdown) In general you don't need to call this method. But you can call it to:
Reimplemented from NLNET::CSock. Definition at line 59 of file dummy_tcp_sock.h.
00059 {} |
|
Connection. You can reconnect a socket after being disconnected. This method does not return a boolean, otherwise a programmer could ignore the result and no exception would be thrown if connection fails :
Reimplemented from NLNET::CTcpSock. Definition at line 39 of file dummy_tcp_sock.cpp.
00040 { 00041 _RemoteAddr = addr; 00042 _Sock = 100; 00043 00044 _BytesReceived = 0; 00045 _BytesSent = 0; 00046 00047 //CSynchronized<bool>::CAccessor sync( &_SyncConnected ); 00048 //sync.value() = true; 00049 _Connected = true; 00050 00051 nldebug( "LNETL0: Socket connected to %s", addr.asString().c_str() ); 00052 } |
|
Returns if the socket is connected (mutexed).
Referenced by NLNET::CCallbackClient::connect(), NLNET::CBufSock::connect(), NLNET::CBufClient::connect(), NLNET::CUdpSimSock::connected(), NLNET::CLoginClient::connectToShard(), NLNET::CBufServer::disconnect(), NLNET::CBufClient::disconnect(), NLNET::CBufSock::pushBuffer(), NLNET::sendEmail(), NLNET::CBufClient::update(), and NLNET::CBufClient::~CBufClient(). |
|
Sets a custom TCP Window size (SO_RCVBUF and SO_SNDBUF). You must close the socket is necessary, before calling this method. See http://www.ncsa.uiuc.edu/People/vwelch/net_perf/tcp_windows.html Definition at line 161 of file tcp_sock.cpp. References addr, NLNET::CSock::createSocket(), and nlerror.
00162 { 00163 // Create socket 00164 if ( _Sock != INVALID_SOCKET ) 00165 { 00166 nlerror( "Cannot connect with custom window size when already connected" ); 00167 } 00168 createSocket( SOCK_STREAM, IPPROTO_TCP ); 00169 00170 // Change window size 00171 if ( setsockopt( _Sock, SOL_SOCKET, SO_SNDBUF, (char*)&windowsize, sizeof(windowsize) ) != 0 00172 || setsockopt( _Sock, SOL_SOCKET, SO_RCVBUF, (char*)&windowsize, sizeof(windowsize) ) != 0 ) 00173 { 00174 throw ESocket( "setWindowSize failed" ); 00175 } 00176 00177 // Connection 00178 CSock::connect( addr ); 00179 } |
|
Creates the socket and get a valid descriptor.
Referenced by NLNET::CListenSock::CListenSock(), NLNET::CTcpSock::connect(), NLNET::CTcpSock::connectWithCustomWindowSize(), and NLNET::CUdpSock::CUdpSock(). |
|
Checks if there is some data to receive, waiting (blocking) at most for the time out value.
Referenced by NLNET::CUdpSimSock::dataAvailable(), and NLNET::CClientReceiveTask::run(). |
|
Returns the socket descriptor.
Definition at line 241 of file sock.h. References NLNET::CSock::_Sock. Referenced by NLNET::CBufSock::asString(), and NLNET::CListenTask::run().
00241 { return _Sock; } |
|
Active disconnection (shutdown) (mutexed). connected() becomes false.
Reimplemented from NLNET::CTcpSock. Definition at line 58 of file dummy_tcp_sock.cpp. References NLNET::CInetAddress::asString(), and nldebug.
00059 { 00060 nldebug( "LNETL0: Socket disconnecting from %s...", _RemoteAddr.asString().c_str() ); 00061 00062 //CSynchronized<bool>::CAccessor sync( &_SyncConnected ); 00063 //sync.value() = false; 00064 _Connected = false; 00065 } |
|
Returns a string explaining the network error (see getLastError()).
|
|
Returns the code of the last error that has occured. Note: This code is platform-dependant. On Unix, it is errno; on Windows it is the Winsock error code. See also errorString() |
|
Gets the send buffer size.
|
|
Returns the TCP Window Size for the current socket.
Definition at line 185 of file tcp_sock.cpp.
00186 { 00187 int windowsize = 0; 00188 socklen_t len = sizeof( windowsize ); 00189 00190 /* send buffer -- query for buffer size */ 00191 if ( getsockopt( _Sock, SOL_SOCKET, SO_SNDBUF, (char*) &windowsize, &len ) == 0 ) 00192 { 00193 return windowsize; 00194 } 00195 else 00196 { 00197 return 0; 00198 } 00199 } |
|
Returns true if the network engine is initialized.
Definition at line 261 of file sock.h.
00261 { return CSock::_Initialized; }
|
|
Initialize the network engine, if it is not already done.
|
|
Returns a const reference on the local address.
Definition at line 235 of file sock.h. References NLNET::CSock::_LocalAddr. Referenced by NLNET::CLoginServer::init(), NLNET::CUdpSimSock::localAddr(), and NLNET::CListenTask::localAddr().
00235 { return _LocalAddr; } |
|
Returns the nonblocking mode.
Definition at line 166 of file sock.h. References NLNET::CSock::_NonBlocking.
00166 { return _NonBlocking; } |
|
Receive a partial or an entire block of data, depending on nonblocking mode. In blocking mode: the method waits until 'len' bytes have been received. In nonblocking mode: the method reads the bytes that have already been received only, and resets 'len' to the number of bytes read. The actual length may be smaller than the demanded length. In no data is available, the return value is CSock::WouldBlock. If dataAvailable() returns true, you are sure that receive() will not return CSock::WouldBlock. In case of graceful disconnection:
In case of failure (e.g. connection reset by peer) :
Reimplemented in NLNET::CUdpSock. Referenced by NLNET::CNonBlockingBufSock::receivePart(), and NLNET::sendEMailCommand(). |
|
Releases the network engine.
|
|
Returns the address of the remote host.
Definition at line 238 of file sock.h. References NLNET::CSock::_RemoteAddr. Referenced by NLNET::CBufServer::hostAddress(), NLNET::CNonBlockingBufSock::receivePart(), NLNET::CBufClient::remoteAddress(), and NLNET::sendEMailCommand().
00238 { return _RemoteAddr; } |
|
Sends a message. In blocking mode: the method waits until 'len' bytes have been sent. In nonblocking mode : the method resets len to the actual number of bytes sent. Even if less bytes than expected have been sent, it returns CSock::Ok. The caller is expected to test the actual len to check if the remaining data must be resent.
Referenced by NLNET::CBufSock::flush(), NLNET::sendEMailCommand(), and NLNET::CUdpSimSock::sendUDPNow(). |
|
Sets the local address.
Referenced by NLNET::CUdpSock::bind(), and NLNET::CUdpSock::sendTo(). |
|
Sets/unsets TCP_NODELAY (by default, it is off, i.e. the Nagle buffering algorithm is enabled). You must call this method *after* connect(). Reimplemented from NLNET::CTcpSock. Definition at line 56 of file dummy_tcp_sock.h. References value.
00056 {} |
|
Sets the socket in nonblocking mode. Call this method *after* connect(), otherwise you will get an "would block" error (10035 on Windows). In nonblocking mode, use received() and sent() instead of receive() and send() Referenced by NLNET::CNonBlockingBufSock::setNonBlocking(). |
|
Sets the send buffer size.
|
|
Change the time out value used in getDataAvailable(), which is 0 by default.
Definition at line 143 of file sock.h. References NLNET::CSock::_TimeoutMs, and NLNET::CSock::_TimeoutS. Referenced by NLNET::CClientReceiveTask::run().
00144 { 00145 _TimeoutS = sec; 00146 _TimeoutMs = ms; 00147 } |
|
Active disconnection for download way only (partial shutdown).
Definition at line 120 of file tcp_sock.cpp.
00121 { 00122 #ifdef NL_OS_WINDOWS 00123 ::shutdown( _Sock, SD_RECEIVE ); 00124 #elif defined NL_OS_UNIX 00125 ::shutdown( _Sock, SHUT_RD ); 00126 #endif 00127 } |
|
Active disconnection for upload way only (partial shutdown).
Definition at line 133 of file tcp_sock.cpp.
00134 { 00135 #ifdef NL_OS_WINDOWS 00136 ::shutdown( _Sock, SD_SEND ); 00137 #elif defined NL_OS_UNIX 00138 ::shutdown( _Sock, SHUT_WR ); 00139 #endif 00140 } |
|
Returns the time out value in millisecond.
Definition at line 244 of file sock.h. References NLNET::CSock::_TimeoutMs, NLNET::CSock::_TimeoutS, and uint32.
00244 { return _TimeoutS*1000 + _TimeoutMs; } |
|
Number of bytes received on this socket.
|
|
Number of bytes sent on this socket.
|
|
True after calling connect().
|
|
Address of local host (valid if connected).
Definition at line 284 of file sock.h. Referenced by NLNET::CSock::localAddr(). |
|
If false, do not log any information.
|
|
If true, the socket is in nonblocking mode.
Definition at line 293 of file sock.h. Referenced by NLNET::CSock::nonBlockingMode(). |
|
Address of the remote host (valid if connected).
Definition at line 287 of file sock.h. Referenced by NLNET::CSock::remoteAddr(). |
|
Socket descriptor.
Definition at line 281 of file sock.h. Referenced by NLNET::CSock::descriptor(). |
|
Secondary time out value (ms) for select in dataAvailable().
Definition at line 309 of file sock.h. Referenced by NLNET::CSock::setTimeOutValue(), and NLNET::CSock::timeOutValue(). |
|
Main time out value (sec) for select in dataAvailable().
Definition at line 306 of file sock.h. Referenced by NLNET::CSock::setTimeOutValue(), and NLNET::CSock::timeOutValue(). |