Skip to content

Instantly share code, notes, and snippets.

@naquad
Created October 16, 2011 17:29
Show Gist options
  • Save naquad/1291166 to your computer and use it in GitHub Desktop.
Save naquad/1291166 to your computer and use it in GitHub Desktop.
ConnectionError ConnectionTCPClient::recv( int timeout )
{
m_recvMutex.lock();
if( m_cancel || m_socket < 0 )
{
m_recvMutex.unlock();
return ConnNotConnected;
}
if( !dataAvailable( timeout ) )
{
m_recvMutex.unlock();
return ConnNoError;
}
int size = static_cast<int>( ::recv( m_socket, m_buf, m_bufsize, 0 ) );
if( size > 0 )
m_totalBytesIn += size;
m_recvMutex.unlock();
if( size <= 0 )
{
ConnectionError error = ( size ? ConnIoError : ConnStreamClosed );
if( m_handler )
m_handler->handleDisconnect( this, error );
return error;
}
m_buf[size] = '\0';
if( m_handler )
m_handler->handleReceivedData( this, std::string( m_buf, size ) );
return ConnNoError;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment