Boost C++ Libraries: Ticket #9723: async_read_until logic bug https://svn.boost.org/trac10/ticket/9723 <p> Hi, </p> <p> Documentation of async_read_until says: "If the streambuf's get area already contains the delimiter, this asynchronous operation completes immediately" </p> <p> However, I noticed that it was not happening and the asynchronous operation was never completing if more data was not received. </p> <p> A logic bug was found in the file <em>boost/asio/impl/read_until.hpp</em> (read_until_delim_op): </p> <pre class="wiki">412 // Check if we're done. 413 if (!start &amp;&amp; bytes_to_read == 0) 414 break; </pre><p> "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. </p> <p> Therefore, the "break" instruction is never reached without first calling at least once async_read_some inside read_until_delim_op. Thus, <strong>the asynchronous operation will never complete immediately</strong> even if the delimiter is already contained in the streambuf's get area. </p> <p> The provided patch fixes the issue. </p> <p> Thanks for amazing asio work, hope this could help. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9723 Trac 1.4.3 anonymous Fri, 28 Feb 2014 10:02:28 GMT attachment set https://svn.boost.org/trac10/ticket/9723 https://svn.boost.org/trac10/ticket/9723 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">read_until.patch</span> </li> </ul> <p> patch that fixes the issue </p> Ticket chris_kohlhoff Mon, 05 May 2014 07:52:49 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9723#comment:1 https://svn.boost.org/trac10/ticket/9723#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> 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 <a class="missing wiki">AsyncReadStream</a> say that a 0-byte read shall complete immediately. If there's a problem here, it is with something not adhering to the <a class="missing wiki">AsyncReadStream</a> requirements. Please reopen if you are able to provide more information as to what that is. </p> Ticket