Opened 9 years ago

Closed 8 years ago

#9723 closed Bugs (invalid)

async_read_until logic bug

Reported by: anonymous Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.55.0 Severity: Showstopper
Keywords: async_read_until Cc:

Description

Hi,

Documentation of async_read_until says: "If the streambuf's get area already contains the delimiter, this asynchronous operation completes immediately"

However, I noticed that it was not happening and the asynchronous operation was never completing if more data was not received.

A logic bug was found in the file boost/asio/impl/read_until.hpp (read_until_delim_op):

412	// Check if we're done.
413	if (!start && bytes_to_read == 0)
414		break;

"start" is true if it is the first operation in the async_read_until composed operation (read_until_delim_op): no async_read_some inside read_until_delim_op has been required yet.

Therefore, the "break" instruction is never reached without first calling at least once async_read_some inside read_until_delim_op. Thus, the asynchronous operation will never complete immediately even if the delimiter is already contained in the streambuf's get area.

The provided patch fixes the issue.

Thanks for amazing asio work, hope this could help.

Attachments (1)

read_until.patch (390 bytes ) - added by anonymous 9 years ago.
patch that fixes the issue

Download all attachments as: .zip

Change History (2)

by anonymous, 9 years ago

Attachment: read_until.patch added

patch that fixes the issue

comment:1 by chris_kohlhoff, 8 years ago

Resolution: invalid
Status: newclosed

According to asio's rules, it must not call the handler from inside the initiating function. In this case the operation does complete immediately, it just uses async_read_some to deliver the completion. You will note that the requirements for an AsyncReadStream say that a 0-byte read shall complete immediately. If there's a problem here, it is with something not adhering to the AsyncReadStream requirements. Please reopen if you are able to provide more information as to what that is.

Note: See TracTickets for help on using tickets.