async_read被async_accept阻止? (升压:: ASIO)

时间:2013-07-18 18:13:22

标签: c++ boost boost-asio

在另一个客户端连接之后才会处理读取。这让我很困惑,看起来很简单。似乎async_accept阻止了所有会话的async_read。

相关摘要 -

server::server(boost::asio::io_service& io_service, int port)
    : io_service_(io_service),
      acceptor_(io_service, tcp::endpoint(tcp::v4(), port))
{
    boost::shared_ptr<session> s(new session(io_service_));
    acceptor_.async_accept(s->socket(),
        boost::bind(&server::handle_accept, this, s,
        boost::asio::placeholders::error));
}

void server::handle_accept(boost::shared_ptr<session> s, 
    const boost::system::error_code& error)
{
    s->start();
    boost::shared_ptr<session> s(new session(io_service_));
    acceptor_.async_accept(s->socket(),
        boost::bind(&server::handle_accept, this, s,
        boost::asio::placeholders::error));
}

void session::start()
{   
    boost::asio::async_read_until(socket_,buffer_,' ',
        boost::bind(&session::handle_read, this, 
            boost::asio::placeholders::error,
            boost::asio::placeholders::bytes_transferred));
}

void session::handle_read(const boost::system::error_code& error, size_t bytes_transferred)
{
    std::cout << "handling read.";
    boost::asio::async_read_until(socket_,buffer_,' ',
        boost::bind(&session::handle_read, this,
        boost::asio::placeholders::error,
        boost::asio::placeholders::bytes_transferred));
}

我在这个基本实现中犯了一些明显的错误吗?

0 个答案:

没有答案