From: claudio Date: Wed, 14 Dec 2022 15:19:16 +0000 (+0000) Subject: Optimize io_buf_read() a bit by calling read() again after the inital X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=97f73431d103310b140c7b7de01a69ba5575449b;p=openbsd Optimize io_buf_read() a bit by calling read() again after the inital header of the buf was read. This often saves a round-trip to the main event loop and poll(2). OK job@ tb@ --- diff --git a/usr.sbin/rpki-client/io.c b/usr.sbin/rpki-client/io.c index 9aedc58fb6c..043331e32b6 100644 --- a/usr.sbin/rpki-client/io.c +++ b/usr.sbin/rpki-client/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.21 2022/11/29 20:26:22 job Exp $ */ +/* $OpenBSD: io.c,v 1.22 2022/12/14 15:19:16 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -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 */