Opened 10 years ago
#8309 new Bugs
[iostreams] bad handling of non-blocking writes for ‘indirect_streambuf’ class
Reported by: | 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:
- Initially,
pbase()
,pptr()
andout().begin()
point to address0x1000
. - 8 characters/bytes are written (assuming char as char_type).
pptr()
is set to0x1008
.- Only 2 characters are consumed downstream.
pbase()
is correctly set to0x1002
.pptr()
remains at0x1008
.- 2 more characters are consumed downstream.
pbase()
is wrongly set to0x1002
. It should be set to0x1004
.
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.
patch