Re: [Boost-users] Boost.Asio -- combining sync read with async read

Igor-- So I'm not sure what you mean exactly by "the server might send a few lines in a bunch." The server will only send one line at a time, in that it will call write_async for every line that it sends-- it will never call write_async on more than one line. However, the client might be doing some processing so the server might send a few lines before the client "comes up for air" next. If that's the case then all three lines will end up in the same buffer when the read_async handler is called? I would imagine so but it would be nice if I could not worry about this, so I am looking for any excuse. =) I also realized upon looking at the chat example in more detail that I missed the whole queue thing that it does. I will aim to replicate that in my app now. In reading through, it occurs to me that I might be making the same mistake with write_async -- i.e. if I call write_async twice in quick succession, that could cause a problem unless I wait for the first write_async to complete before I call write_async a second time? Best, -Sameer On Oct 14, 2009, at 6:21 PM, boost-users-request@lists.boost.org wrote:
If this is the case in your application (i.e. the server might send few lines in a bunch), then I think yes, you have to inspect the sterambuf manually. Actually, this is the reason I never used read_until - in most cases it doesn't make your code simpler. The one case where it does is when your protocol has a text header and a body (like in HTTP).

On Thu, Oct 15, 2009 at 9:47 AM, Sameer Parekh
So I'm not sure what you mean exactly by "the server might send a few lines in a bunch." The server will only send one line at a time, in that it will call write_async for every line that it sends-- it will never call write_async on more than one line. However, the client might be doing some processing so the server might send a few lines before the client "comes up for air" next. If that's the case then all three lines will end up in the same buffer when the read_async handler is called?
Yes, just because the server program called write 3 distinct times, doesn't mean that this will equate to 3 reads on the client side. The actual number of reads depends on many factors, both software- and hardware-related. Jon

So I'm not sure what you mean exactly by "the server might send a few lines in a bunch." The server will only send one line at a time, in that it will call write_async for every line that it sends-- it will never call write_async on more than one line.
I meant to say: "if your protocol doesn't oblige the server to wait for client's acknowledge after every line."
However, the client might be doing some processing so the server might send a few lines before the client "comes up for air" next. If that's the case then all three lines will end up in the same buffer when the read_async handler is called?
Right.
In reading through, it occurs to me that I might be making the same mistake with write_async -- i.e. if I call write_async twice in quick succession, that could cause a problem unless I wait for the first write_async to complete before I call write_async a second time?
Yes, it was discussed several times: http://groups.google.com/group/boost-list/browse_thread/thread/a75fd0a362383...
participants (3)
-
Igor R
-
Jonathan Franklin
-
Sameer Parekh