Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Asio -- combining sync read with async read
From: Sameer Parekh (sameer_at_[hidden])
Date: 2009-10-14 15:40:16


> Right. The most simple way to accomplish this is to use
> asio::streambuf as a
> buffer. When you process the input data, you call consume() function
> only
> for the amout you've really processed, and the rest of the data
> remains
> unused in the streambuf - until the next time you get something from
> the
> server (look at the asio examples with streambuf).

Yes, I'm using the streambuf, and then constructing an istream from
the streambuf, and then calling getline on the istream. (The chat
client/server was the primary example that I used to build my app.)

If I have 2.5 lines in the buffer then the first two calls to getline
will give me the first two lines, but won't the third call to getline
get me
the half line, and consume that half line from the streambuf? Do I
need to process the streambuf in a more manual fashion rather than
calling getline on the istream?

Also to make sure I understand it how it works with the streambuf,
that I am understanding you correctly: if I was just processing one
line in the async_handler, and the first time the server sends me 3
lines, then the handler is called and will process the first line
sent. Then the server sends another 3 lines, the async handler is
called and the client will process the 2nd line that it received, not
the 4th line, right?

Thanks for your help,
-Sameer


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