rpki-client IO buffers start with a small header (the size of the full
message) followed by the payload. io_buf_read() currently does this in
two steps. Because of this simple messages require two calls through the
event loop and poll(2) for one message.
By retrying the read after parsing the header this double loop can be
skipped if the full message was present in the socketbuffer.
The result is a minor reduction in processing time.
Before:
Processing time 192 seconds (175 seconds user, 30 seconds system)
After:
Processing time 182 seconds (165 seconds user, 28 seconds system)
--
:wq Claudio
Index: io.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/io.c,v
retrieving revision 1.21
diff -u -p -r1.21 io.c
--- io.c 29 Nov 2022 20:26:22 -0000 1.21
+++ io.c 11 Dec 2022 10:33:04 -0000
@@ -189,10 +189,13 @@ io_buf_read(int fd, struct ibuf **ib)
*ib = b;
}
+ again:
/* read some data */
while ((n = read(fd, b->buf + b->wpos, b->size - b->wpos)) == -1) {
if (errno == EINTR)
continue;
+ if (errno == EAGAIN)
+ return NULL;
err(1, "read");
}
@@ -209,7 +212,7 @@ io_buf_read(int fd, struct ibuf **ib)
errx(1, "bad internal framing, bad size");
if (ibuf_realloc(b, sz) == -1)
err(1, "ibuf_realloc");
- return NULL;
+ goto again;
}
/* skip over initial size header */