Opened 11 years ago
Closed 10 years ago
#6576 closed Bugs (fixed)
boost:::iostreams::file_descriptor throws instead of reading EOF on pipe
Reported by: | Owned by: | Jonathan Turkanis | |
---|---|---|---|
Milestone: | To Be Determined | Component: | iostreams |
Version: | Boost 1.48.0 | Severity: | Problem |
Keywords: | pipe read ReadFile CreatePipe | Cc: | maihem@… |
Description
when using file_descriptor to read from a pipe on windows, an exception can be thrown if the write-side has broken the pipe - eg by exiting if it's another process.
This is how I used the read-side of the pipe to trigger the failure (if you need a complete minimal sample including windows pipe and process handling code, please ask). I just used CreateProcess to start a cmd.exe shell script that echo'd a couple of lines to stdout. The pipe has less than the default buffer size written before the write side is closed:
file_descriptor fd(pipe_read_side_handle); newline_filter nl(newline::posix); filtered_istream fs; fs.push(nl); fs.push(fd); string str; getline(fs, str);
fs.good() is now false
expected: fs.good() should be true here getline(fs, str); getline(fs, str); ... eventually fs.eof() should be true getline(fs, str); one more getline then fs.fail() should be true. I think there are a few different behaviours depending on whether there is a trailing newline or not but I think fs.badbit should not be set
Attachments (3)
Change History (6)
by , 11 years ago
Attachment: | file_descriptor.cpp added |
---|
comment:1 by , 10 years ago
I can confirm the bug (tested with Boost 1.50.0). I can also confirm that the proposed bug fix works (file_descriptor_impl::read should return -1 when GetLastError returns ERROR_BROKEN_PIPE). I've attached two test programs which can be used to reproduce the problem and to test a possible fix.
comment:3 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
fixed version of file_descriptor.cpp