J
James Kanze
You seem to be agreeing with me. It wouldn't make sense for a
read on a pipe to block until all N requested bytes are
available. Consider e.g. what happens if the final piece of
data is M < N. It has to return M.
In the classical implementation of pipes (under Unix V7, for
example), a read from a pipe blocked until either the requested
number of bytes were read, or all writers had closed the
connection (the file descriptor). That handles the final piece
of data, but it means that you can easily hang in between.
The classical way of handling this, if you couldn't get the
length otherwise, was to read one byte (so you'd block if
nothing was available), then do an fstat to find out how many
more were there, and read them.