async_read_until() and have it call my fill handler when it receives something.Then the function that submits orders would callwrite()and then block waiting for the ack message usingread_until()However, when I implement that, the client never seems to notice that a fill message is sent. It receives the acks just fine, and it successfully reads the datafeed coming in from the other tcp connection. I thought maybe the read_until() would cancel the async_read_until() so after I received the ack message I called async_read_until() again, but that didn't work either...(The server works as it should, I tested it with telnet.)Is it possible to mix sync/async reads in this way? Can anyone tell if I am doing something wrong? Do I need to do something else to make this work?
Aha, thanks Igor. So my handler needs to be able to deal with a buffer
that contains more than one line. That's not so bad, I can just run
the processing code for each line until the buffer is empty, that
should be fine.
However, what concerns me is if the handler receives a buffer that has
just 2.5 lines in it. All the messages from the server are going to be
one line long. So if the server sends three messages in succession but
say there is some network hiccup partway through the 3rd line, then my
client will only receive 2.5 lines, and the handler will get called
with the partial line? Then the handler has to cache the partial line
so that when the rest of the line comes through it can paste them
together again? That seems hard...
thanks,
-s
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
However, what concerns me is if the handler receives a buffer that has just 2.5 lines in it. All the messages from the server are going to be one line long. So if the server sends three messages in succession but say there is some network hiccup partway through the 3rd line, then my client will only receive 2.5 lines, and the handler will get called with the partial line? Then the handler has to cache the partial line so that when the rest of the line comes through it can paste them together again? That seems hard...
> 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