Re: [Boost-users] Boost.Asio -- combining sync read with async read
No, it will read anything available in the socket and put it in the buffer. It can be 1 line, 2 lines or 3.25 lines. What I mean is that you have to be aware of the fact that the buffer might contain more data than you "requested" from read_until.
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
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).
participants (2)
-
Igor R
-
Sameer Parekh