2

We have a member function in some .h file

template <typename MutableBufferSequence> 
int read_some(boost::asio::ip::tcp::socket& sock, 
    const MutableBufferSequence& buffers) 
{
    return sock.read_some(buffers);
}

And such code we want to have in one of our class functions:

boost::packaged_task<int> pt(boost::bind(&http_request::read_some, this, &socket, boost::asio::buffer(buffer, buffer_size)));

This gives me 87 compiler errors and talls me that boost::bind does not work this way. I wonder how to pass boost::asio::buffer via boost::bind to my function?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Rella
  • 65,003
  • 109
  • 363
  • 636

1 Answers1

1

You have to tell the compiler which read_some you want to bind. Since it's a template, you have to specify the template parameter when you pass it in to bind().

In your case you want http_request::read_some<boost::asio::mutable_buffers_1>.

As a side note, you're also passing in the socket object itself wrong. You're passing in a pointer to the socket, and the function takes a reference. Instead of passing in &socket to bind, pass in boost::ref(socket), alternatively you can make the function take a socket pointer instead of reference.

Arvid
  • 10,915
  • 1
  • 32
  • 40