boost:asio:read_until问题与boost::bind有关

boost:asio:read_until issue with boost::bind

本文关键字:boost 有关 问题 bind asio read until      更新时间:2023-10-16

我在编译这段代码时遇到问题错误

/usr/include/boost/bind_mf_cc.hpp:91:5:错误:初始化'boost::_bi::bind_t的参数5,typename boost::_blai::list_av_4::type>boost:;bind(R(t::*)(B1,B2,B3),A1,A2,A3,A4)[其中R=void;T=tcpReader;B1=const boost::system::error_code&B2=unsigned int;B3=boost::asio::basic_streambuf<>&A1=tcpReader*;A2=boost::system:;error_code;A3=unsignedint;A4=boost::asic_streambuf<>;typename boost:_bi::list_av_4:type=boost _bi::value>>]

void tcpReader::handle_read(const boost::system::error_code& ec, std::size_t bytes_transferred, boost::asio::streambuf& buf)
// inside a class method
boost::asio::streambuf buf;
boost::asio::async_read_until(*sock,buf,"n" ,
                              boost::bind(&tcpReader::handle_read,this,error,buf.size(),buf)
                              );

有什么问题吗?我知道我错过了一些简单的东西,但我不知道是不是我必须使用boot::buffer?

提前感谢

对我来说,async_read_until()的所有重载都需要两个参数。您传递一个有3个参数的函数。如果您想将流作为额外的参数传递,请将其绑定到函数以获得一个具有2个参数的函数。

boost::bind( &tcpReader::handle_read, this, _1, _2, boost::ref( buf ) )

将您的成员函数"转换"为某种东西,需要2个参数。boost::ref()将缓冲区包装为引用,否则将生成一个副本。

亲切问候Torsten