0

I am having an issue compiling this piece of code error

/usr/include/boost/bind/bind_mf_cc.hpp:91:5: error: initializing argument 5 of ‘boost::_bi::bind_t, typename boost::_bi::list_av_4::type> boost::bind(R (T::*)(B1, B2, B3), A1, A2, A3, A4) [with 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 = unsigned int; A4 = boost::asio::basic_streambuf<>; typename boost::_bi::list_av_4::type = boost::_bi::list4, boost::_bi::value, boost::_bi::value, 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)
                              );

Any ideas on what the problem is ? It I know I am missing something simple but I cannot figure it out is it something like I will have to use boot::buffer ?

Thanks in advance

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
gda2004
  • 718
  • 13
  • 32
  • should you be using `boost::asio::placeholders::error`, and `boost::asio::placeholders::bytes_transferred` instead of `err` and `buf.size()` respectively? – Chad Jul 17 '12 at 15:34
  • 1
    You also may need to wrap the last paremeter `buf` with `boost::ref(buf)`. – Chad Jul 17 '12 at 15:35

1 Answers1

1

To me it looks like, that all overloads of async_read_until() takes 2 arguments. You pass a function with 3 arguments. Likely you want to pass the stream as extra parameter, bind it to the function to get a function with 2 arguments.

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

Will "convert" your member function to something, that takes 2 arguments. The boost::ref() wraps your buffer as reference, otherwise a copy would be made.

Kind regards Torsten

Torsten Robitzki
  • 3,041
  • 1
  • 21
  • 35
  • It now appears that my function is never called for some reason I do not see any output from handle_read any ideas ? – gda2004 Jul 17 '12 at 15:48
  • 1
    @gda2004 From you example, it looks like that the stream buffer isn't associated with any kind of tcp socket. – Torsten Robitzki Jul 17 '12 at 15:57
  • @gda2004 you are right, so *sock is the expression that denotes the socket. If your callback isn't triggered, I would assume, that no data was written or, that the "\n" wasn't read. You can use a tool like wire shark to analyze the network traffic. – Torsten Robitzki Jul 17 '12 at 19:41