Boost logo

Boost Users :

Subject: [Boost-users] [asio] skipping data in tcp stream
From: Roman Shmelev (rshmelev_at_[hidden])
Date: 2009-03-29 18:28:40

What we have:
tcp connection, from which we read messages.
each message = header(fixed len) + body(random len)
header contains the length of body and crc to check if the header is
not corrupted.

Reading is done in two async steps - first the header is read, then
memory for body is allocated and the body is read.
Questions are:
1) if header is corrupted under some cases (header crc says body len
could be wrong) then as I understand we must skip all body data and
read the next message.
How to skip? async_read_until seemed to be the solution, but manual
told that it may read surplus data into streambuf - it will be hard to
deal with that data because I am reading directly from socket to some
allocated memory (as was told above)
2) actually, can it be that in tcp stream data will be corrupted? I
guess, yes - so header contains bodylen and crc for body and for
header? is such solution an overhead?
3) maybe I do some global design mistakes?

Thank you!

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at