asio flushing a buffer

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 ______________________________________ Scanned and protected by Email scanner

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?
Any read operation puts the data in the buffer you supply to it, so you can do anything you wish with that data, including throwing it away. But what could be the purpose of such a step? If you get some data from your peer, it usually has some meaning, doesn't it?

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
participants (3)
-
Igor R
-
Lloyd
-
Michael Caisse