|
Boost : |
Subject: [boost] [asio] buffered_read_stream issue, with async_read()
From: brad higgins (bhiggins_at_[hidden])
Date: 2009-06-04 15:31:46
Hi,
I am using boost asio in a project. My program has a TCP protocol
which reads a fixed size message header, followed by a variable-sized
message body. It is possible to have a message with a 0-byte body,
and it is possible that no messages are received for some time.
I have an issue when attempting to async_read() a 0-byte body with
the buffered_read_stream, detailed here:
(1) My program reads a fixed-sized header
(2) After this succeeds, my program issues an async read for 0 bytes,
for the message body
(3) buffered_read_stream sees that storage_ is empty, so it calls
async_fill(), to fill it
(4) no more messages arrive for some time, so there is no data
available to fill
(5) BUG -> My program's 0-byte read timer expires, rather than the
read() succeeding and calling my handler immediately
If I use the boost::asio::tcp::socket instead of the
buffered_read_stream, the 0-byte read occurs immediately, and does not
time out. I believe the read() with the buffered_read_stream is
getting 'blocked' in async_fill(), rather than succeeding immediately.
Do you think the buffered_read_stream should have special cases for
0 byte reads to cover this case, or do you think client code should
avoid issuing 0 byte reads?
Thanks,
Brad
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk