[Bug libstdc++/21286] [4.0/4.1 Regression] filebuf::xsgetn vs pipes
ncm-nospam at cantrip dot org
gcc-bugzilla@gcc.gnu.org
Sat Apr 30 02:12:00 GMT 2005
------- Additional Comments From ncm-nospam at cantrip dot org 2005-04-30 02:11 -------
Just to add... if sgetn() loops reading until it gets n bytes, but
underflow() accepts a pipe's short reads, then in_avail() will report
the size of the short read. Then, istream::read_some() will
rdbuf->sgetn(p,rdbuf->in_avail()), thus matching POSIX pipe semantics
when attached to a pipe.
(For those who don't know: as long as whoever is writing the
other end of the pipe writes no more than PIPE_BUF bytes into
it, then POSIX requires that read() deliver the bytes on write
boundaries. Thus, if you're writing structs, the reader will
see half a struct. If you're writing short-enough lines, the
reader will only ever see complete lines -- although you might
see more than one. Watch out that PIPE_BUF is 4K or more
on Linux, but only 512 bytes on BSD!)
It's exciting to finally get this right. With a bit more work,
I see now that we might be able to support nonblocking file
descriptors, and maybe even zero-copy I/O, too! Thank you, Ralf.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21286
More information about the Gcc-bugs
mailing list