diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2020-10-26 21:31:16 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska-skaware@skarnet.org> | 2020-10-26 21:31:16 +0000 |
| commit | bc714f8001edbb26ebf07411cf92e9ba2f756b35 (patch) | |
| tree | e0812fa851135a518209640876b1dc4dd9b7dfad /src/libunixonacid/textmessage_create_send_channel.c | |
| parent | 7530e8cdd506ecec1f4ad3bbd55f94de5a6d63ac (diff) | |
| download | skalibs-bc714f8001edbb26ebf07411cf92e9ba2f756b35.tar.gz | |
Refactor textmessage/textclient with channel creation around ancil_*
Diffstat (limited to 'src/libunixonacid/textmessage_create_send_channel.c')
| -rw-r--r-- | src/libunixonacid/textmessage_create_send_channel.c | 47 |
1 files changed, 47 insertions, 0 deletions
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 <errno.h> +#include <string.h> + +#include <skalibs/djbunix.h> +#include <skalibs/unix-timed.h> +#include <skalibs/ancil.h> +#include <skalibs/textmessage.h> +#include <skalibs/textclient.h> +#include <skalibs/posixishard.h> + +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 ; +} |
