简体   繁体   中英

Asio async_read_some template error

I'm writing a simple asynchronous server using non-boost asio. I've come across a huge template error, and frankly, I can't even begin to imagine what it all means.

For reference, my code looks very much like http://think-async.com/Asio/asio-1.5.3/src/examples/http/server3/connection.cpp .

Here is my code:

void client_connection::serve()
{
    // std::cout << "Began serving connection" << std::endl;
    // refer to http server 3 connection.cpp
    this->socket_.async_read_some(asio::buffer(&protocol_version_, 1), this->strand_.wrap(std::bind(&client_connection::handle_read, this->shared_from_this(), asio::placeholders::error, asio::placeholders::bytes_transferred)));

    // 65535 max tcp size
}

void client_connection::handle_read(const asio::error_code& error_, std::size_t bytes_)
{
    if (error_) return;

    // for debug: print out all the recieved bytes
    std::cout << std::hex << protocol_version_ << " " << std::endl;
    this->serve();
}

Here is the error:

1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional(1152): error : no instance of overloaded function "std::_Pmf_wrap<_Pmf_t, _Rx, _Farg0, _V0_t, _V1_t, std::_Nil, std::_Nil, std::_Nil, std::_Nil, std::_Nil>::operator() [with _Pmf_t=void (client_connection::*)(const asio::error_code &, size_t={unsigned int}), _Rx=void, _Farg0=client_connection, _V0_t=const asio::error_code &, _V1_t=size_t={unsigned int}]" matches the argument list
1>              argument types are: (client_connection *, boost::arg<1>, boost::arg<2>)
1>              object type is: std::_Pmf_wrap<void (client_connection::*)(const asio::error_code &, size_t), void, client_connection, const asio::error_code &, size_t, std::_Nil, std::_Nil, std::_Nil, std::_Nil, std::_Nil>
1>    _VARIADIC_EXPAND_0X(_CLASS_BIND, , , , )
1>    ^
(+~20 not very relevant lines)

I had a hunch it was related to shared_from_this, but the error occurs whether or not I remove the shared_from_this behavior.

Help of any form is greatly appreciated.

I believe that the asio::placeholders::* work with boost::bind , but I'm not so sure that they work with std::bind . Try std::placeholders::_1 and std::placeholders::_2 instead, or use boost::bind .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM