Move fd flow code into flow.c
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 *);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 *);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user