12
我使用這個代碼讀取使用流緩衝緩衝升壓ASIO讀寫
socket_.async_read_some(boost::asio::buffer(data_, max_length),
boost::bind(&session::handle_read, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
,這寫
boost::asio::async_write(socket_,
boost::asio::buffer(data_, bytes_transferred),
boost::bind(&session::handle_write, this,
boost::asio::placeholders::error));
其中socket_的插座,MAX_LENGTH是用枚舉值1024 data_是長度爲max_length的char數組。
但我想用streambuf替換char數組緩衝區。我試過
boost::asio::streambuf streamBuffer;
socket_.async_read_some(boost::asio::buffer(streamBuffer),
boost::bind(&session::handle_read, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
但是不行。我該怎麼做 ?