c++ - Asio async_read_some 模板错误

标签 c++ boost-asio

我正在使用非 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.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)

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

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

最佳答案

我相信 asio::placeholders::*boost::bind 一起工作,但我不确定它们是否与 std 一起工作::绑定(bind)。尝试使用 std::placeholders::_1std::placeholders::_2,或者使用 boost::bind

关于c++ - Asio async_read_some 模板错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15862111/

相关文章:

Python - 将有符号 float 转换为无符号长整数(win32 为 DWORD)

C++ PNG header missread IHDR data chunk 长宽高

c++ - 在 c++ asio 中,如何为 http 或 https 创建相同的套接字对象(接口(interface)/抽象问题?)

error-handling - 如何映射Windows系统错误代码以增强::error_condition?

c++ - Boost.Asio IPv6 为什么绑定(bind)错误?

C++ win32 更改轨迹栏背景颜色

c++编码选择开关代码上的每个案例

c++ - 是否可以在 C++ 中重载 ""?

c++ - Visual Studio C++ 阅读标题

c++ - 无法从 'const boost::asio::const_buffers_1' 转换为 'boost::asio::mutable_buffer'