Re: [PATCH 3/8] xread_nonblock: add functionality to read from fds without blocking
- From
Jeff King <peff@peff.net>
- Date
- Dec 14, 2015, 23:57 UTC
- Message-ID
- <20151214235736.GA26133@sigill.intra.peff.net>
- In-Reply-To
- <xmqqio40hbam.fsf@gitster.mtv.corp.google.com>
On Mon, Dec 14, 2015 at 03:15:29PM -0800, Junio C Hamano wrote:
Show 9 quoted lines
> -- >8 -- > From: Stefan Beller <sbeller@google.com> > Date: Mon, 14 Dec 2015 11:37:13 -0800 > Subject: [PATCH] xread_nonblock: add functionality to read from fds without blocking > > 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.
This makes me wonder why we restart xread() on EAGAIN in the first place.
On EINTR, sure; signals can come and we want to keep going. But if do not have non-blocking descriptors, it should never happen, right?
Are we trying to protect ourselves against somebody _else_ giving us a non-blocking descriptor? In that case we'll quietly spin and waste CPU. Which isn't great, but perhaps better than returning an error.
-Peff