コード例 #1
0
void TFtp::Session::HandlerWrite(const sys::error_code &e,
                                 size_t                 bytes) {
  if (e) {
    std::cerr << e.message() << std::endl;
  }
  AsyncAccept();
}
コード例 #2
0
void TFtp::Session::HandlerRead(const sys::error_code &e,
                                size_t                 bytes) {
  if (e) {
    std::cerr << e.message() << std::endl;
    return;
  }
  DetectInputPkt();
}
コード例 #3
0
ファイル: connection.cpp プロジェクト: merlimat/DistMap
void Connection::handleReceive( const ConnectionPtr& cnx,
                                SharedBuffer& buffer,
                                bool isFirstPart,
                                const sys::error_code& error,
                                size_t size )
{
    if ( error || size == 0 )
    {
        TRACE( "Error reading data: " << error.message() );
        return;
    }

    if ( isFirstPart )
    {
        uint32_t msgSize = readMessageSize( buffer );
        TRACE( "Msg size: " << msgSize << " -- Read Size: " << size );

        if ( msgSize > size )
        {
            // Schedule a complete read
            buffer.resize( msgSize );
            asio::async_read( m_socket, asio::buffer( buffer.data() + size,
                    msgSize - size ), bind( &Connection::handleReceive, this,
                    cnx, buffer, false, ph::error, ph::bytes_transferred ) );
            return;
        }
    }

    TRACE( "Got the complete message" );
    /// Do something....
    Message msg;
    readMessageWithSize( buffer, msg );
    switch ( msg.type() )
    {
    case Message::NodeList:
    {
        TRACE( "Node list received: " );
        m_membership.receivedNodeList( msg.nodelist() );
        receiveMessage();
        break;
    }
    case Message::Ping:
    {
        TRACE( "Ping msg received" );
        SharedBuffer buffer;
        if ( !msg.ping().has_nodelist() )
            buffer = CreatePongMsg();
        else
        {
            m_membership.receivedNodeList( msg.ping().nodelist() );
            DEBUG( "Resending the node list with pong message" );
            buffer = CreatePongMsg( m_membership.nodeList() );
        }

        asio::async_write( m_socket, buffer, bind( &Connection::handleSend,
                this, cnx, ph::error, ph::bytes_transferred ) );
        break;
    }
    default:
    {
        ERROR( "Invalid msg received." );
        dumpBuffer( std::cerr, buffer.data(), buffer.size() );
        break;
    }
    }
}