]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add buf_flush_to_pipe() and buf_read_from_pipe().
authorAlexander Færøy <ahf@torproject.org>
Mon, 10 Sep 2018 12:42:29 +0000 (14:42 +0200)
committerAlexander Færøy <ahf@torproject.org>
Tue, 27 Nov 2018 18:31:08 +0000 (19:31 +0100)
This patch adds two new functions: buf_flush_to_pipe() and
buf_read_from_pipe(), which makes use of our new buf_flush_to_fd() and
buf_read_from_fd() functions.

See: https://bugs.torproject.org/28179

src/lib/net/buffers_net.c
src/lib/net/buffers_net.h

index 7c81096e38c7e1579ea7bc3d07df636a3b43cf49..1b65819dbbddce29808fcd5ad48851e06ea16b5c 100644 (file)
@@ -239,3 +239,29 @@ buf_read_from_socket(buf_t *buf, tor_socket_t s, size_t at_most,
 {
   return buf_read_from_fd(buf, s, at_most, reached_eof, socket_error, true);
 }
+
+/** Write data from <b>buf</b> to the pipe <b>fd</b>.  Write at most
+ * <b>sz</b> bytes, decrement *<b>buf_flushlen</b> by
+ * the number of bytes actually written, and remove the written bytes
+ * from the buffer.  Return the number of bytes written on success,
+ * -1 on failure.  Return 0 if write() would block.
+ */
+int
+buf_flush_to_pipe(buf_t *buf, int fd, size_t sz,
+                  size_t *buf_flushlen)
+{
+  return buf_flush_to_fd(buf, fd, sz, buf_flushlen, false);
+}
+
+/** Read from pipe <b>fd</b>, writing onto end of <b>buf</b>.  Read at most
+ * <b>at_most</b> bytes, growing the buffer as necessary.  If read() returns 0
+ * (because of EOF), set *<b>reached_eof</b> to 1 and return 0. Return -1 on
+ * error; else return the number of bytes read.
+ */
+int
+buf_read_from_pipe(buf_t *buf, int fd, size_t at_most,
+                   int *reached_eof,
+                   int *socket_error)
+{
+  return buf_read_from_fd(buf, fd, at_most, reached_eof, socket_error, false);
+}
index 417f6f9413ab3208465feece9b868287fb2a5af1..8911b082a27ffa5c31bba071f37d6ab69fd12113 100644 (file)
@@ -24,4 +24,11 @@ int buf_read_from_socket(struct buf_t *buf, tor_socket_t s, size_t at_most,
 int buf_flush_to_socket(struct buf_t *buf, tor_socket_t s, size_t sz,
                         size_t *buf_flushlen);
 
+int buf_read_from_pipe(struct buf_t *buf, int fd, size_t at_most,
+                       int *reached_eof,
+                       int *socket_error);
+
+int buf_flush_to_pipe(struct buf_t *buf, int fd, size_t sz,
+                      size_t *buf_flushlen);
+
 #endif /* !defined(TOR_BUFFERS_H) */