On Mon, Sep 21, 2015 at 6:39 PM, Stefan Beller <sbeller@xxxxxxxxxx> wrote: > From the man page: > [...] > So if we get an EAGAIN or EWOULDBLOCK error the fd must be nonblocking. s/So/&,/ s/error/&,/ > As the intend of xread is to read as much as possible either until the s/intend/intent/ > fd is EOF or an actual error occurs, we can ease the feeder of the fd > by not spinning the whole time, but rather wait for it politely by not > busy waiting. > > Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> > --- > --- a/wrapper.c > +++ b/wrapper.c > @@ -201,8 +201,23 @@ ssize_t xread(int fd, void *buf, size_t len) > len = MAX_IO_SIZE; > while (1) { > nr = read(fd, buf, len); > - if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) > - continue; > + if (nr < 0) { > + if (errno == EINTR) > + continue; > + if (errno == EAGAIN || errno == EWOULDBLOCK) { > + struct pollfd pfd; > + int i; > + pfd.events = POLLIN; > + pfd.fd = fd; > + i = poll(&pfd, 1, 100); Why is this poll() using a timeout? Isn't that still a busy wait of sorts (even if less aggressive)? > + if (i < 0) { > + if (errno == EINTR || errno == ENOMEM) > + continue; > + else > + die_errno("poll"); > + } > + } > + } > return nr; > } > } > -- > 2.5.0.275.ge015d2a -- 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