Hi,

 

I am using Asio in Boost version  1.36.0 and I have a question regarding boost::asio::streambuf.

 

Code extract:

Class A

{

boost::asio::streambuf buf;//class member

 

void Read()

{

boost::asio::async_read_until(socket, buf, boost::regex(“\0101”),boost::bind(DoSomething,this,boost::asio::placeholders::error,boost::asio::placeholders::bytes_transfered));//class function

}

 

void DoSomething(const boost::system::error_code& ec, std::size_t bytes_transferred)//class function

{

If(!ec && (bytes_transferred != 0))

{

boost::asio::streambuf::const_buffers_type bufs = buf.data();

std::string s(boost::asio::buffers_begin(bufs),boost::asio::buffers_begin(bufs) + bytes_transferred);

//Do something with the data in s;

 

//Here I need to call async_read_until again, but buf still has the data read in the earlier call so,  it calls the DoSomething handler again thus repeating //the process.

Read();

}             

}

};

 

My question is how do I clear the contents of buf before calling async_read_until again. I tried reading into a local variable but boost::asio::streambuf is noncopyable. Is there a better way to do what I am trying to do. Any help is greatly appreciated.