Re: [PATCH 01/10] strbuf: Add strbuf_read_noblock
- From
Jeff King <peff@peff.net>
- Date
- Sep 17, 2015, 16:57 UTC
- Message-ID
- <20150917165724.GA27102@sigill.intra.peff.net>
- In-Reply-To
- <CAPc5daVY=t27wkX2x7DSfObwxZuv37VYxi1XD-RKiS1mv4=6KA@mail.gmail.com>
On Thu, Sep 17, 2015 at 09:44:19AM -0700, Junio C Hamano wrote:
Show 5 quoted lines
> > Arguably we should actually return the number of bytes we _did_ read, > > but then caller cannot easily tell the difference between EOF and > > EAGAIN. > > Why can't it check errno==EAGAIN/EWOULDBLOCK?
Is it trustworthy to check errno if read() has not actually ever returned -1? E.g., consider this sequence:
1. somebody (maybe even us calling strbuf_read) calls read() and it
returns -1, setting errno to EAGAIN2. we call strbuf_read()
2a. it calls read(), which returns N bytes
2b. it calls read() again, which returns 0 for EOF
2c. it returns N, because that's how many bytes it read
3. we wonder if we hit EOF, or if we simply need to read again. We
check errno == EAGAINI don't think the read calls in step 2 are guaranteed to clear errno, and we might read the cruft from step 1.
-Peff