[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Add buf_flush_to_pipe() and buf_read_from_pipe().



commit 31b3a6577c89492e94836f6e3b4bfc7051a3dc7a
Author: Alexander Færøy <ahf@xxxxxxxxxxxxxx>
Date:   Mon Sep 10 14:42:29 2018 +0200

    Add buf_flush_to_pipe() and buf_read_from_pipe().
    
    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 | 26 ++++++++++++++++++++++++++
 src/lib/net/buffers_net.h |  7 +++++++
 2 files changed, 33 insertions(+)

diff --git a/src/lib/net/buffers_net.c b/src/lib/net/buffers_net.c
index 7c81096e3..1b65819db 100644
--- a/src/lib/net/buffers_net.c
+++ b/src/lib/net/buffers_net.c
@@ -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);
+}
diff --git a/src/lib/net/buffers_net.h b/src/lib/net/buffers_net.h
index 417f6f941..8911b082a 100644
--- a/src/lib/net/buffers_net.h
+++ b/src/lib/net/buffers_net.h
@@ -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) */



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits