async_read_some模板错误

Asio async_read_some template error

本文关键字:错误 some read async      更新时间:2023-10-16

我正在使用非boost asio编写一个简单的异步服务器。我遇到了一个巨大的模板错误,坦率地说,我甚至无法想象这一切意味着什么。

作为参考,我的代码看起来很像http://think-async.com/Asio/asio-1.5.3/src/examples/http/server3/connection.cpp .

下面是我的代码:
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();
}

错误如下:

1>C:Program Files (x86)Microsoft Visual Studio 11.0VCincludefunctional(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)

我有预感它与shared_from_this有关,但无论我是否删除shared_from_this行为,错误都会发生。

任何形式的帮助都是非常感谢的。

我相信asio::placeholders::*boost::bind一起工作,但我不确定他们是否与std::bind一起工作。尝试std::placeholders::_1std::placeholders::_2代替,或使用boost::bind