C++ 如何将Boost::asio::buffer(buf,size)与Boost绑定一起使用?
我们在某个.h文件中有一个成员函数C++ 如何将Boost::asio::buffer(buf,size)与Boost绑定一起使用?,c++,boost,boost-asio,boost-bind,C++,Boost,Boost Asio,Boost Bind,我们在某个.h文件中有一个成员函数 template <typename MutableBufferSequence> int read_some(boost::asio::ip::tcp::socket& sock, const MutableBufferSequence& buffers) { return sock.read_some(buffers); } 模板 int read_some(boost::asio::ip::tcp::s
template <typename MutableBufferSequence>
int read_some(boost::asio::ip::tcp::socket& sock,
const MutableBufferSequence& buffers)
{
return sock.read_some(buffers);
}
模板
int read_some(boost::asio::ip::tcp::socket和sock,
常量可变缓冲区序列和缓冲区)
{
返回sock.read_一些(缓冲区);
}
我们希望在类函数中包含这样的代码:
boost::packaged_task<int> pt(boost::bind(&http_request::read_some, this, &socket, boost::asio::buffer(buffer, buffer_size)));
boost::packaged_任务pt(boost::bind(&http_请求::read_some,this,&socket,boost::asio::buffer(buffer,buffer_size)));
这给了我87个编译器错误,并告诉我boost::bind不能以这种方式工作。我想知道如何通过
boost::asio::buffer
将boost::bind
传递给我的函数?你必须告诉编译器你想绑定哪个读取一些。由于它是一个模板,因此在将其传递到bind()
时必须指定模板参数
在您的情况下,您需要http\u请求::read\u some
作为旁注,您还错误地传入了套接字对象本身。您正在传递一个指向套接字的指针,而函数接受一个引用。不要将&socket
传递到bind
,而是传递boost::ref(socket)
,或者,您可以让函数采用套接字指针而不是引用。作为boost::bind()的第三个参数传递的socket
变量的类型是什么?