3

I have small piece of code

boost::asio::ip::tcp::no_delay option(true);
boost::asio::ip::tcp::socket* sock = new boost::asio::ip::tcp::socket(ios);
sock->set_option(option);
_session_acceptor.async_accept(*sock, 
                boost::bind(&server::playerAccept, this, sock, boost::asio::placeholders::error));

If i call set_option on socket before accepting server dont accept any connections. But if i call set_option after connections are accepted. Is there any magic?

4

1 回答 1

4

您应该调用set_option接受器,而不是套接字。我的项目中的示例:

 Listener::Listener(int port)
            : acceptor(io, ip::tcp::endpoint(ip::tcp::v4(), port))
            , socket(io) {
    boost::asio::ip::tcp::no_delay opt_nodelay(true);
    acceptor.set_option(opt_nodelay);
    start_accept();
于 2012-09-23T18:56:14.880 回答