From bb77e8c7230b8d87fd5c3f08ab8aceb8cb945b9b Mon Sep 17 00:00:00 2001 From: Claudio Jeker Date: Sat, 23 Oct 2021 16:06:05 +0000 Subject: Finnally move away from blocking reads in rpki-client. The code was a mish mash of poll, non-blocking writes and blocking reads. Using the introduced ibuf size header in io_buf_new()/io_buf_close() the read side can be changed to pull in a full ibuf and only start the un-marshal once all data has been read. OK benno@ --- usr.sbin/rpki-client/rsync.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'usr.sbin/rpki-client/rsync.c') diff --git a/usr.sbin/rpki-client/rsync.c b/usr.sbin/rpki-client/rsync.c index 6b115447cdb..839250b03e7 100644 --- a/usr.sbin/rpki-client/rsync.c +++ b/usr.sbin/rpki-client/rsync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rsync.c,v 1.26 2021/10/22 11:13:06 claudio Exp $ */ +/* $OpenBSD: rsync.c,v 1.27 2021/10/23 16:06:04 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -120,6 +120,7 @@ proc_rsync(char *prog, char *bind_addr, int fd) int rc = 0; struct pollfd pfd; struct msgbuf msgq; + struct ibuf *b, *inbuf = NULL; sigset_t mask, oldmask; struct rsyncproc *ids = NULL; @@ -178,7 +179,7 @@ proc_rsync(char *prog, char *bind_addr, int fd) for (;;) { char *uri = NULL, *dst = NULL; - size_t id, size; + size_t id; pid_t pid; int st; @@ -198,7 +199,6 @@ proc_rsync(char *prog, char *bind_addr, int fd) */ while ((pid = waitpid(WAIT_ANY, &st, WNOHANG)) > 0) { - struct ibuf *b; int ok = 1; for (i = 0; i < idsz; i++) @@ -247,11 +247,17 @@ proc_rsync(char *prog, char *bind_addr, int fd) if (!(pfd.revents & POLLIN)) continue; + b = io_buf_read(fd, &inbuf); + if (b == NULL) + continue; + /* Read host and module. */ - io_simple_read(fd, &size, sizeof(size)); - io_simple_read(fd, &id, sizeof(id)); - io_str_read(fd, &dst); - io_str_read(fd, &uri); + io_read_buf(b, &id, sizeof(id)); + io_read_str(b, &dst); + io_read_str(b, &uri); + + ibuf_free(b); + assert(dst); assert(uri); -- cgit v1.2.3