The point of sanitize_read() is to convert the return code of a reading
function (that roughly has the same interface as read()) into a return
code that flows more naturally in an asynchronous non-blocking program.
That means, -1 EWOULDBLOCK is a normal condition where there's no data
to read at the moment, and EOF is an exceptional condition, signaling
either the end of the loop or an error.
So, sanitize_read turns -1 EWOULDBLOCK into 0, and 0 into -1 EPIPE.
Why EPIPE? Because *no system I know uses EPIPE anywhere in a reading
function*. EPIPE is only ever returned by system calls that *write*
data, when they write to a pipe that has broken.
Since sanitize_read() is only used after a reading function, -1 EPIPE
is not a possible input. If the output of sanitize_read() is -1 EPIPE,
it necessarily means that the reading function returned 0, i.e. EOF.
There is no conflation, sanitize_read() is a bijection.
If there is a reading function that can return -1 EPIPE someday,
then I'll reassess. But I doubt it will ever happen.
--
Laurent
Received on Tue Jun 30 2026 - 18:30:36 CEST