Boost logo

Boost Users :

Subject: Re: [Boost-users] asio flushing a buffer
From: Michael Caisse (boost_at_[hidden])
Date: 2010-04-09 11:04:56


Lloyd wrote:
> Hi,
>
> I went through the documentation of boost::asio::read_until()
> function. It says that if some data left in the stream after a
> read_until() operation, it will be available in the next "read"
> opration from the stream. Is there any way to "flush" (simply remove)
> the unwanted data from the stream so as to receive entirely new data
> than the old "useless" data left in the stream?
>
> Thanks,
> Lloyd
>

Hi Lloyd -

Just to be clear. If you had a read_until that was looking for an 'A'
and a data stream such as this:

   B E J DDE E KA JJE K

In addition to have up to the 'A' in your buffer, you may have some
amount of data following the 'A'. The "old useless" data left in the
stream is not bogus bytes from the bit-bucket. It is data that follows
your search pattern.

Think of it this way. If your stream is from a TCP connection and ASIO
is searching for an 'A', it will get the data currently available from
the TCP layer and begin the search. If it finds the pattern in the
available data set then it is done. But there may be more data in the
search buffer than was needed. You will very likely want to keep that
"extra" around because it is part of the next "message".

HTH -
michael

-- 
----------------------------------
Michael Caisse
Object Modeling Designs
www.objectmodelingdesigns.com

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