Re: [PATCH 4/8] strbuf: add strbuf_read_once to read without blocking
- From
- Eric Sunshine <ericsunshine@gmail.com>
- Date
- Dec 14, 2015, 23:16 UTC
- Message-ID
- <CAPig+cQUGCFZnOxjuFaYNNhLqfdS7thrUQKqNkr5=0Hr4OkyMw@mail.gmail.com>
- In-Reply-To
- <1450121838-7069-5-git-send-email-sbeller@google.com>
On Mon, Dec 14, 2015 at 2:37 PM, Stefan Beller <sbeller@google.com> wrote:
Show 19 quoted lines
> The new call will read from a file descriptor into a strbuf once. The > underlying call xread_nonblock is meant to execute without blocking if > the file descriptor is set to O_NONBLOCK. It is a bug to call > strbuf_read_once on a file descriptor which would block. > > Signed-off-by: Stefan Beller <sbeller@google.com> > Signed-off-by: Junio C Hamano <gitster@pobox.com> > --- > diff --git a/strbuf.h b/strbuf.h > @@ -367,6 +367,14 @@ extern size_t strbuf_fread(struct strbuf *, size_t, FILE *); > extern ssize_t strbuf_read(struct strbuf *, int fd, size_t hint); > > /** > + * Returns the number of new bytes appended to the sb. > + * Negative return value signals there was an error returned from > + * underlying read(2), in which case the caller should check errno. > + * e.g. errno == EAGAIN when the read may have blocked. > + */ > +extern ssize_t strbuf_read_once(struct strbuf *, int fd, size_t hint);
strbuf_read_once() is a rather opaque name; without reading the documentation, it's difficult to figure out what it means. I wonder if strbuf_read_nonblock() or something would be clearer?