Thread (18 messages) 18 messages, 3 authors, 2016-06-15

Re: [PATCH 4/8] strbuf: add strbuf_read_once to read without blocking

flat view

From: Eric Sunshine <hidden>
Date: 2016-06-15 23:07:27

On Mon, Dec 14, 2015 at 2:37 PM, Stefan Beller [off-list ref] wrote:
quoted hunk ↗ jump to hunk
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 <redacted>
Signed-off-by: Junio C Hamano <redacted>
---
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?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help