Boost C++ Libraries: Ticket #8309: [iostreams] bad handling of non-blocking writes for ‘indirect_streambuf’ class https://svn.boost.org/trac10/ticket/8309 <p> When a non-blocking write is done, the <code>indirect_streambuf</code> class sets the pointer to the start of the put area (<code>pbase()</code>) to the start of his own internal buffer (<code>out().buffer()</code>) offset by the number of bytes consumed. </p> <p> This algorithm works with a single non-blocking write but fails with multiple successive non-blocking writes. </p> <p> Imagine the following scenario: </p> <ol><li>Initially, <code>pbase()</code>, <code>pptr()</code> and <code>out().begin()</code> point to address <code>0x1000</code>. </li><li>8 characters/bytes are written (assuming char as char_type). </li><li><code>pptr()</code> is set to <code>0x1008</code>. </li><li>Only 2 characters are consumed downstream. </li><li><code>pbase()</code> is correctly set to <code>0x1002</code>. <code>pptr()</code> remains at <code>0x1008</code>. </li><li>2 more characters are consumed downstream. </li><li><strong><code>pbase()</code> is wrongly set to <code>0x1002</code></strong>. It should be set to <code>0x1004</code>. </li></ol><p> I have attached a <a class="attachment" href="https://svn.boost.org/trac10/attachment/ticket/8309/nonblocking_indirect_streambuf_write.cpp" title="Attachment 'nonblocking_indirect_streambuf_write.cpp' in Ticket #8309">file containing a sample unit-test</a><a class="trac-rawlink" href="https://svn.boost.org/trac10/raw-attachment/ticket/8309/nonblocking_indirect_streambuf_write.cpp" title="Download">​</a> that reproduces this scenario. </p> <p> The fix looks easy as the <code>pbase()</code> pointer needs to be set to its previous value offset by the number of bytes consumed. I have attached a <a class="attachment" href="https://svn.boost.org/trac10/attachment/ticket/8309/indirect_streambuf.hpp.patch" title="Attachment 'indirect_streambuf.hpp.patch' in Ticket #8309">patch</a><a class="trac-rawlink" href="https://svn.boost.org/trac10/raw-attachment/ticket/8309/indirect_streambuf.hpp.patch" title="Download">​</a> that implements this fix and makes the unit-test pass. However I am unable to assess the impact or correctness of this fix. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8309 Trac 1.4.3 fpascutti@… Tue, 19 Mar 2013 09:26:59 GMT attachment set https://svn.boost.org/trac10/ticket/8309 https://svn.boost.org/trac10/ticket/8309 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">indirect_streambuf.hpp.patch</span> </li> </ul> <p> patch </p> Ticket fpascutti@… Tue, 19 Mar 2013 09:27:36 GMT attachment set https://svn.boost.org/trac10/ticket/8309 https://svn.boost.org/trac10/ticket/8309 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">nonblocking_indirect_streambuf_write.cpp</span> </li> </ul> <p> unit-test </p> Ticket