summaryrefslogtreecommitdiff
path: root/src/libunixonacid/textclient_start.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-10-26 21:31:16 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-10-26 21:31:16 +0000
commitbc714f8001edbb26ebf07411cf92e9ba2f756b35 (patch)
treee0812fa851135a518209640876b1dc4dd9b7dfad /src/libunixonacid/textclient_start.c
parent7530e8cdd506ecec1f4ad3bbd55f94de5a6d63ac (diff)
downloadskalibs-bc714f8001edbb26ebf07411cf92e9ba2f756b35.tar.xz
Refactor textmessage/textclient with channel creation around ancil_*
Diffstat (limited to 'src/libunixonacid/textclient_start.c')
-rw-r--r--src/libunixonacid/textclient_start.c46
1 files changed, 9 insertions, 37 deletions
diff --git a/src/libunixonacid/textclient_start.c b/src/libunixonacid/textclient_start.c
index 3074ae3..e8a6d0c 100644
--- a/src/libunixonacid/textclient_start.c
+++ b/src/libunixonacid/textclient_start.c
@@ -4,48 +4,23 @@
#include <string.h>
#include <errno.h>
-#include <skalibs/allreadwrite.h>
-#include <skalibs/error.h>
#include <skalibs/webipc.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 ssize_t get (void *p)
-{
- int *fd = p ;
- int r = ancil_recv_fd(fd[0], '|') ;
- if (r < 0) return error_isagain(errno) ? (errno = 0, 0) : r ;
- fd[1] = r ;
- return 1 ;
-}
-
int textclient_start (textclient_t *a, char const *path, uint32_t options, char const *before, size_t beforelen, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp)
{
struct iovec v ;
- int fd[2] ;
- ssize_t r ;
- fd[0] = ipc_stream_nbcoe() ;
- if (fd[0] < 0) return 0 ;
- if (!ipc_timed_connect(fd[0], path, deadline, stamp)) goto err ;
- textmessage_sender_init(&a->syncout, fd[0]) ;
+ int fd = ipc_stream_nbcoe() ;
+ if (fd < 0) return 0 ;
+ if (!ipc_timed_connect(fd, path, deadline, stamp)) goto err ;
+ textmessage_sender_init(&a->syncout, fd) ;
if (!textmessage_timed_send(&a->syncout, before, beforelen, deadline, stamp)) goto ferr ;
- textmessage_receiver_init(&a->syncin, fd[0], a->syncbuf, TEXTCLIENT_BUFSIZE, TEXTMESSAGE_MAXLEN) ;
- r = timed_get(fd, &getfd, &get, deadline, stamp) ;
- if (!r) errno = EPIPE ;
- if (r <= 0) goto aerr ;
- if (sanitize_read(textmessage_timed_receive(&a->syncin, &v, deadline, stamp)) <= 0) goto perr ;
- if (v.iov_len != afterlen || memcmp(v.iov_base, after, afterlen)) { errno = EPROTO ; goto perr ; }
- textmessage_receiver_init(&a->asyncin, fd[1], a->asyncbuf, TEXTCLIENT_BUFSIZE, TEXTMESSAGE_MAXLEN) ;
- if (sanitize_read(textmessage_timed_receive(&a->asyncin, &v, deadline, stamp)) <= 0) goto serr ;
+ if (!textmessage_recv_channel(fd, &a->asyncin, a->asyncbuf, TEXTCLIENT_BUFSIZE, after, afterlen, deadline, stamp)) goto ferr ;
+ textmessage_receiver_init(&a->syncin, fd, a->syncbuf, TEXTCLIENT_BUFSIZE, TEXTMESSAGE_MAXLEN) ;
+ if (!textclient_timed_get(a, &v, deadline, stamp)) goto aerr ;
if (v.iov_len != afterlen || memcmp(v.iov_base, after, afterlen)) goto berr ;
a->pid = 0 ;
a->options = options & ~TEXTCLIENT_OPTION_WAITPID ;
@@ -53,15 +28,12 @@ int textclient_start (textclient_t *a, char const *path, uint32_t options, char
berr:
errno = EPROTO ;
- serr:
- textmessage_receiver_free(&a->asyncin) ;
- perr:
- fd_close(fd[1]) ;
aerr:
textmessage_receiver_free(&a->syncin) ;
+ textmessage_receiver_free(&a->asyncin) ;
ferr:
textmessage_sender_free(&a->syncout) ;
err:
- fd_close(fd[0]) ;
+ fd_close(fd) ;
return 0 ;
}