Boost logo

Boost Users :

Subject: [Boost-users] boost::asio::streambuf question
From: Amit Sonawane (asonawane_at_[hidden])
Date: 2008-10-13 16:33:44


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::placehol
ders::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.

 

 

Esta mensagem pode conter informação confidencial e/ou privilegiada. Se você não for o destinatário ou a pessoa autorizada a receber esta mensagem, não deverá utilizar, copiar, alterar, divulgar a informação nela contida ou tomar qualquer ação baseada nessas informações. Se você recebeu esta mensagem por engano, por favor avise imediatamente o remetente, respondendo o e-mail e em seguida apague-o. Agradecemos sua cooperação.

This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, change, take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net