From 20bc50795deaa8dcfebedbeedf00d15cceb0fcdf Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Wed, 2 Mar 2016 19:16:23 -0800 Subject: [PATCH] Move fd flow code into flow.c --- adsbus/file.c | 7 ------- adsbus/file.h | 1 - adsbus/flow.c | 8 ++++++++ adsbus/flow.h | 1 + adsbus/opts.c | 7 +++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/adsbus/file.c b/adsbus/file.c index 93b1a52..c4d38c1 100644 --- a/adsbus/file.c +++ b/adsbus/file.c @@ -134,13 +134,6 @@ void file_cleanup() { } } -// TODO: this code probably belongs elsewhere -void file_fd_new(int fd, struct flow *flow, void *passthrough) { - // TODO: log error - flow_hello(fd, flow, passthrough); - flow->new(fd, passthrough, NULL); -} - void file_read_new(char *path, struct flow *flow, void *passthrough) { file_new(path, O_RDONLY, flow, passthrough); } diff --git a/adsbus/file.h b/adsbus/file.h index 75f7c87..7727a49 100644 --- a/adsbus/file.h +++ b/adsbus/file.h @@ -3,7 +3,6 @@ struct flow; void file_cleanup(void); -void file_fd_new(int, struct flow *, void *); void file_read_new(char *, struct flow *, void *); void file_write_new(char *, struct flow *, void *); void file_append_new(char *, struct flow *, void *); diff --git a/adsbus/flow.c b/adsbus/flow.c index b7db29c..99d19e7 100644 --- a/adsbus/flow.c +++ b/adsbus/flow.c @@ -23,3 +23,11 @@ bool flow_hello(int fd, struct flow *flow, void *passthrough) { } return (write(fd, buf_at(buf_ptr, 0), buf_ptr->length) == (ssize_t) buf_ptr->length); } + +bool flow_new(int fd, struct flow *flow, void *passthrough) { + if (!flow_hello(fd, flow, passthrough)) { + return false; + } + flow->new(fd, passthrough, NULL); + return true; +} diff --git a/adsbus/flow.h b/adsbus/flow.h index ddacf0a..1e3bb07 100644 --- a/adsbus/flow.h +++ b/adsbus/flow.h @@ -16,3 +16,4 @@ struct flow { void flow_socket_connected(int, struct flow *); bool flow_hello(int, struct flow *, void *); +bool flow_new(int, struct flow *, void *); diff --git a/adsbus/opts.c b/adsbus/opts.c index a4ba5c6..e29ec7f 100644 --- a/adsbus/opts.c +++ b/adsbus/opts.c @@ -8,6 +8,7 @@ #include "exec.h" #include "file.h" +#include "flow.h" #include "incoming.h" #include "outgoing.h" #include "receive.h" @@ -135,8 +136,7 @@ bool opts_add_exec_send(char *arg) { bool opts_add_stdin(char __attribute__((unused)) *arg) { int fd = fcntl(0, F_DUPFD_CLOEXEC, 0); assert(fd >= 0); - file_fd_new(fd, receive_flow, NULL); - return true; + return flow_new(fd, receive_flow, NULL); } bool opts_add_stdout(char *arg) { @@ -146,6 +146,5 @@ bool opts_add_stdout(char *arg) { } int fd = fcntl(1, F_DUPFD_CLOEXEC, 0); assert(fd >= 0); - file_fd_new(fd, send_flow, serializer); - return true; + return flow_new(fd, send_flow, serializer); }