From: Jeff King Date: Wed, 23 Sep 2015 01:51:27 GMT Subject: Re: [PATCHv3 02/13] xread: poll on non blocking fds Message-ID: <20150923015127.GC21294@sigill.intra.peff.net> In-Reply-To: On Tue, Sep 22, 2015 at 05:14:42PM -0700, Stefan Beller wrote: > We should not care if the call to poll failed, as we're in an infinite loop and > can only get out with the correct read(..). So maybe an implementation like this > would already suffice: > > ssize_t xread(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 == EAGAIN || errno == EWOULDBLOCK) { > struct pollfd pfd; > pfd.events = POLLIN; > pfd.fd = fd; > /* We deliberately ignore the return value of poll. */ > poll(&pfd, 1, -1); > continue; > } > } > return nr; > } > } FWIW, that is what I had imagined. -Peff