From bc714f8001edbb26ebf07411cf92e9ba2f756b35 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 26 Oct 2020 21:31:16 +0000 Subject: Refactor textmessage/textclient with channel creation around ancil_* --- .../textmessage_create_send_channel.c | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/libunixonacid/textmessage_create_send_channel.c (limited to 'src/libunixonacid/textmessage_create_send_channel.c') diff --git a/src/libunixonacid/textmessage_create_send_channel.c b/src/libunixonacid/textmessage_create_send_channel.c new file mode 100644 index 0000000..40f7ff7 --- /dev/null +++ b/src/libunixonacid/textmessage_create_send_channel.c @@ -0,0 +1,47 @@ +/* ISC license. */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +static int getfd (void *p) +{ + return ((int *)p)[0] ; +} + +static int one (void *p) +{ + (void)p ; + return 1 ; +} + +static int sendit (void *p) +{ + int *fd = p ; + return ancil_send_fd(fd[0], fd[1], '|') ; +} + +int textmessage_create_send_channel (int sock, textmessage_sender_t *asyncout, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp) +{ + int fd[3] = { sock } ; + int r ; + if (pipenbcoe(fd+1) < 0) return 0 ; + r = timed_flush(fd, &getfd, &one, &sendit, deadline, stamp) ; + fd_close(fd[1]) ; + if (!r) goto err ; + textmessage_sender_init(asyncout, fd[2]) ; + if (!textmessage_timed_send(asyncout, after, afterlen, deadline, stamp)) goto ferr ; + return 1 ; + + ferr: + textmessage_sender_free(asyncout) ; + err: + fd_close(fd[2]) ; + return 0 ; +} -- cgit v1.3.1