Subject: [Boost-bugs] [Boost C++ Libraries] #8309: [iostreams] bad handling of non-blocking writes for âindirect_streambufâ class
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-03-19 09:26:27
#8309: [iostreams] bad handling of non-blocking writes for âindirect_streambufâ
class
-------------------------------+--------------------------------------------
Reporter: fpascutti@⦠| Owner: turkanis
Type: Bugs | Status: new
Milestone: To Be Determined | Component: iostreams
Version: Boost 1.53.0 | Severity: Problem
Keywords: |
-------------------------------+--------------------------------------------
When a non-blocking write is done, the {{{indirect_streambuf}}} class sets
the pointer to the start of the put area ({{{pbase()}}}) to the start of
his own internal buffer ({{{out().buffer()}}}) offset by the number of
bytes consumed.
This algorithm works with a single non-blocking write but fails with
multiple successive non-blocking writes.
Imagine the following scenario:
1. Initially, {{{pbase()}}}, {{{pptr()}}} and {{{out().begin()}}} point to
address {{{0x1000}}}.
2. 8 characters/bytes are written (assuming char as char_type).
3. {{{pptr()}}} is set to {{{0x1008}}}.
4. Only 2 characters are consumed downstream.
5. {{{pbase()}}} is correctly set to {{{0x1002}}}. {{{pptr()}}} remains at
{{{0x1008}}}.
6. 2 more characters are consumed downstream.
7. **{{{pbase()}}} is wrongly set to {{{0x1002}}}**. It should be set to
{{{0x1004}}}.
I have attached a
[[attachment:nonblocking_indirect_streambuf_write.cpp|file containing a
sample unit-test]] that reproduces this scenario.
The fix looks easy as the {{{pbase()}}} pointer needs to be set to its
previous value offset by the number of bytes consumed. I have attached a
[[attachment:indirect_streambuf.hpp.patch|patch]] that implements this fix
and makes the unit-test pass. However I am unable to assess the impact or
correctness of this fix.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/8309> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:12 UTC