From: Eric Sunshine Date: Mon, 14 Dec 2015 23:05:10 GMT Subject: Re: [PATCH 3/8] xread_nonblock: add functionality to read from fds without blocking Message-ID: In-Reply-To: On Mon, Dec 14, 2015 at 6:03 PM, Eric Sunshine wrote: > On Mon, Dec 14, 2015 at 2:37 PM, Stefan Beller wrote: >> Provide a wrapper to read(), similar to xread(), that restarts on >> EINTR but not EAGAIN (or EWOULDBLOCK). This enables the caller to >> handle polling itself, possibly polling multiple sockets or performing >> some other action. >> >> Signed-off-by: Stefan Beller >> --- >> diff --git a/wrapper.c b/wrapper.c >> @@ -252,6 +252,28 @@ ssize_t xread(int fd, void *buf, size_t len) >> + * xread_nonblock() is the same a read(), but it automatically restarts read() >> + * interrupted operations (EINTR). xread_nonblock() DOES NOT GUARANTEE that >> + * "len" bytes is read. EWOULDBLOCK is turned into EAGAIN. > > The last sentence is confusing. From the commit message, we learn that > this function doesn't care about EAGAIN or EWOULDBLOCK, yet the above > comment seems to imply that it does. What it really ought to be saying > is that "as a convenience, errno is transformed from EWOULDBLOCK to > EAGAIN so that the caller only has to check for EAGAIN". I forgot to mention that the mutation of EWOULDBLOCK into EAGAIN is something that should be described in the header rather than here at the source. In fact, the entire comment block above this function is more suitable in the header file.