Opened 10 years ago

#8309 new Bugs

[iostreams] bad handling of non-blocking writes for ‘indirect_streambuf’ class

Reported by: fpascutti@… Owned by: Jonathan Turkanis
Milestone: To Be Determined Component: iostreams
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc:

Description

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 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 patch that implements this fix and makes the unit-test pass. However I am unable to assess the impact or correctness of this fix.

Attachments (2)

indirect_streambuf.hpp.patch (473 bytes ) - added by fpascutti@… 10 years ago.
patch
nonblocking_indirect_streambuf_write.cpp (1.3 KB ) - added by fpascutti@… 10 years ago.
unit-test

Download all attachments as: .zip

Change History (2)

by fpascutti@…, 10 years ago

patch

by fpascutti@…, 10 years ago

unit-test

Note: See TracTickets for help on using tickets.