Use streambuf as buffer for boost asio read and write

后端 未结 1 1182
南笙
南笙 2021-02-07 10:18

I\'m using this code for reading

  socket_.async_read_some(boost::asio::buffer(data_, max_length),
        boost::bind(&session::handle_read, this,
                 


        
相关标签:
1条回答
  • 2021-02-07 11:09

    You need to get a mutable_buffers_type from the streambuf to use as your first parameter to async_read_some.

      boost::asio::streambuf streamBuffer;
      boost::asio::streambuf::mutable_buffers_type mutableBuffer =
          streamBuffer.prepare(max_length);
      socket_.async_read_some(boost::asio::buffer(mutableBuffer),
            boost::bind(&session::handle_read, this,
            boost::asio::placeholders::error,
            boost::asio::placeholders::bytes_transferred));
    

    See the asio documentation here and here for more info.

    0 讨论(0)
提交回复
热议问题