PStreams now has an improved implementation of
pstreambuf::showmanyc() which makes
streambuf::in_avail() far more useful. Previously
it only worked on some platforms and although it would tell
you how many characters could be read from the underlying
pipe without
blocking, if that number was less than the
pstreambuf::bufsz then there was no way to read only
that many characters from the
streambuf without
blocking. This is because
underflow will try to fill
the whole buffer, blocking until sufficient characters are
available. (That behaviour actually makes
in_avail() almost
useless, I probably should have been doing
avail -=
avail%bufsz in the old
showmanyc() code.)
The new showmanyc() code will immediately read as
many characters as are available into the buffer, in
non-blocking mode. This
means that
if you always check for available characters using
streambuf::in_avail() and ensure you don't read more
than that (e.g. by using
istream::readsome() or istream::get()) then
the parent process should never have to block waiting for
data from the child.
The next step is to generalise this by providing a
select()-like function, so you don't have to poll the
two pipes connected to the child process' stdout and
stderr. This is more important for the development
branch where there could be any number of pipes shared
between parent and child.