From 716cc2b4b0f4aa2e92b0bc75220128a49cd0921a Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Tue, 24 Mar 2020 21:24:26 -0400 Subject: [PATCH] Check expiries when no IO is ready --- x5/khatus.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/x5/khatus.c b/x5/khatus.c index ce7db95..6ffa538 100644 --- a/x5/khatus.c +++ b/x5/khatus.c @@ -316,7 +316,7 @@ opts_parse(Config *cfg, int argc, char *argv[]) } void -fifo_expire_one(Fifo *f, struct timespec t, char *buf) +fifo_expire(Fifo *f, struct timespec t, char *buf) { struct timespec td; @@ -328,15 +328,6 @@ fifo_expire_one(Fifo *f, struct timespec t, char *buf) } } -void -fifo_expire_all(Config *cfg, struct timespec t, char *buf) -{ - Fifo *f; - - for (f = cfg->fifos; f; f = f->next) - fifo_expire_one(f, t, buf); -} - void fifo_read_error(Fifo *f, char *buf) { @@ -440,7 +431,8 @@ fifo_read_all(Config *cfg, struct timespec *ti, char *buf) debug("ready: %d\n", ready); assert(ready >= 0); clock_gettime(CLOCK_MONOTONIC, &t); - while (ready) { + /* At-least-once ensures that expiries are still checked on timeouts. */ + do { for (Fifo *f = cfg->fifos; f; f = f->next) { if (FD_ISSET(f->fd, &fds)) { debug("reading: %s\n", f->name); @@ -471,9 +463,11 @@ fifo_read_all(Config *cfg, struct timespec *ti, char *buf) default: assert(0); } + } else { + fifo_expire(f, t, buf); } } - } + } while (ready); assert(ready == 0); } @@ -563,14 +557,6 @@ main(int argc, char *argv[]) puts(buf); fflush(stdout); } - - /* - * This is a good place for expiry check, since we're about to - * sleep anyway and the time taken by the check will be - * subtracted from the sleep period. - */ - fifo_expire_all(cfg, t0, buf); - clock_gettime(CLOCK_MONOTONIC, &t1); // FIXME: check errors timespecsub(&t1, &t0, &td); debug("td {tv_sec = %ld, tv_nsec = %ld}\n", td.tv_sec, td.tv_nsec); -- 2.20.1