ConnectionError ConnectionTCPServer::recv( int timeout )
{
    m_recvMutex.lock();

    if( m_cancel || m_socket < 0 || !m_connectionHandler )
    {
        m_recvMutex.unlock();
        return ConnNotConnected;
    }

    if( !dataAvailable( timeout ) )
    {
        m_recvMutex.unlock();
        return ConnNoError;
    }

    struct sockaddr_in they;
    int sin_size = sizeof( struct sockaddr_in );
#ifdef WIN32
    int newfd = accept( m_socket, (struct sockaddr*)&they, &sin_size );
#else
    int newfd = accept( m_socket, (struct sockaddr*)&they, (socklen_t*)&sin_size );
#endif

    m_recvMutex.unlock();

    ConnectionTCPClient* conn = new ConnectionTCPClient( m_logInstance, inet_ntoa( they.sin_addr ),
            ntohs( they.sin_port ) );
    conn->setSocket( newfd );
    m_connectionHandler->handleIncomingConnection( conn );

    return ConnNoError;
}
  ConnectionError ConnectionTCPServer::recv( int timeout )
  {
    m_recvMutex.lock();

    if( m_cancel || m_socket < 0 || !m_connectionHandler )
    {
      m_recvMutex.unlock();
      return ConnNotConnected;
    }

    if( !dataAvailable( timeout ) )
    {
      m_recvMutex.unlock();
      return ConnNoError;
    }

    struct sockaddr_storage they;
    int addr_size = sizeof( struct sockaddr_storage );
#if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
    int newfd = static_cast<int>( accept( static_cast<SOCKET>( m_socket ), (struct sockaddr*)&they, &addr_size ) );
#else
    int newfd = accept( m_socket, (struct sockaddr*)&they, (socklen_t*)&addr_size );
#endif

    m_recvMutex.unlock();

    char buffer[INET6_ADDRSTRLEN];
    char portstr[NI_MAXSERV];
    int err = getnameinfo( (struct sockaddr*)&they, addr_size, buffer, sizeof( buffer ),
                           portstr, sizeof( portstr ), NI_NUMERICHOST | NI_NUMERICSERV );
    if( !err )
      return ConnIoError;

    ConnectionTCPClient* conn = new ConnectionTCPClient( m_logInstance, buffer,
                                                         atoi( portstr ) );
    conn->setSocket( newfd );
    m_connectionHandler->handleIncomingConnection( this, conn );

    return ConnNoError;
  }