On Mon, Dec 14, 2015 at 2:37 PM, Stefan Beller <sbeller@xxxxxxxxxx> 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 <sbeller@xxxxxxxxxx> > --- > 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". (It also feels weird that this should be messing with errno at all, but that's a different issue...) > + */ > +ssize_t xread_nonblock(int fd, void *buf, size_t len) > +{ > + ssize_t nr; > + if (len > MAX_IO_SIZE) > + len = MAX_IO_SIZE; > + while (1) { > + nr = read(fd, buf, len); > + if (nr < 0) { > + if (errno == EINTR) > + continue; > + if (errno == EWOULDBLOCK) > + errno = EAGAIN; > + } > + return nr; > + } > +} -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html