Re: [PATCHv3 02/13] xread: poll on non blocking fds
- From
Jeff King <peff@peff.net>
- Date
- Sep 22, 2015, 19:49 UTC
- Message-ID
- <20150922194927.GA622@sigill.intra.peff.net>
- In-Reply-To
- <xmqqy4fy2q6o.fsf@gitster.mtv.corp.google.com>
On Tue, Sep 22, 2015 at 12:45:51PM -0700, Junio C Hamano wrote:
Show 16 quoted lines
> Jacob Keller <jacob.keller@gmail.com> writes: > > > I don't think this patch actually changes behavior as it stands now. I > > think Junio's suggestion does. Personally, I'd prefer some sort of > > warning when you use xread and get EAGAIN or EWOULDBLOCK. I'd rather > > see it somehow warn so that we can find the bug (since we really > > really shouldn't be calling xread with a blocking socket, especially > > if we have xread_noblock or similar as in this series. > > One caveat is that the caller may not know in the first place. > > The last time I checked the existing callers of xread(), there were > a few that read from a file descriptor they did not open themselves > (e.g. unpack-objects that read from standard input). The invoker of > these processes is free to do O_NONBLOCK their input stream for > whatever reason.
Yeah. I do not think this is a bug at all; the user might have their reasons for handing off an O_NONBLOCK pipe. If we take xread() to mean "try to read from fd until we get a real error, some data, or an EOF", then it is perfectly reasonable to replace spinning on read() (which we do now) with a poll() for efficiency. The caller (and the user) does not have to care, and should not notice; the outcome will be the same.
-Peff