Ejemplo n.º 1
0
void ConnectionManager::handle_write(boost::system::error_code const& e, MessagePointer message, ConnectionPointer conn)
{
#if TIME_WRITES
    static virvo::FrameCounter counter;

    printf("CM: writes/sec: %.2f\n", counter.registerFrame());
#endif

    // Call the connection's slot
    conn->signal_(Connection::Write, message, e);

    // Remove the message from the queue
    write_queue_.pop_front();

    if (!e)
    {
        // Message successfully sent.
        // Send the next one -- if any.
        if (!write_queue_.empty())
        {
            do_write();
        }
    }
    else
    {
#ifndef NDEBUG
        printf("ConnectionManager::handle_write: %s", e.message().c_str());
#endif

        remove_connection(conn);
    }
}
Ejemplo n.º 2
0
void ConnectionManager::handle_read_data(boost::system::error_code const& e, MessagePointer message, ConnectionPointer conn)
{
#if TIME_READS
    static virvo::FrameCounter counter;

    printf("CM: reads/sec: %.2f\n", counter.registerFrame());
#endif

    // Call the connection's slot
    conn->signal_(Connection::Read, message, e);

    if (!e)
    {
        // Read the next message
        do_read(conn);
    }
    else
    {
#ifndef NDEBUG
        printf("ConnectionManager::handle_read_data: %s", e.message().c_str());
#endif

        remove_connection(conn);
    }
}
Ejemplo n.º 3
0
void ConnectionManager::handle_read_data(boost::system::error_code const& e, MessagePointer message, ConnectionPointer conn)
{
    // Call the connection's slot
    conn->signal_(Connection::Read, message, e);

    if (!e)
    {
        // Read the next message
        do_read(conn);
    }
    else
    {
#ifndef NDEBUG
        printf("ConnectionManager::handle_read_data: %s", e.message().c_str());
#endif

        remove_connection(conn);
    }
}
Ejemplo n.º 4
0
void ConnectionManager::handle_read_header(boost::system::error_code const& e, MessagePointer message, ConnectionPointer conn)
{
    if (!e)
    {
        //
        // TODO:
        // Need to deserialize the message-header!
        //

        // Allocate memory for the message data
        message->data_.resize(message->header_.size_);

        assert( message->header_.size_ != 0 );
        assert( message->header_.size_ == message->data_.size() );

        // Start an asynchronous call to receive the data.
        boost::asio::async_read(
                conn->socket_,
                boost::asio::buffer(&message->data_[0], message->data_.size()),
                boost::bind(&ConnectionManager::handle_read_data, this, boost::asio::placeholders::error, message, conn)
                );
    }
    else
    {
#ifndef NDEBUG
        printf("ConnectionManager::handle_read_header: %s", e.message().c_str());
#endif

#if 1
        // Call the connection's slot
        conn->signal_(Connection::Read, message, e);
#endif
        // Delete the connection
        remove_connection(conn);
    }
}