From d5becb1a234d56fb107be7411d3692b572086733 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 18 Jan 2019 08:31:12 -0600 Subject: Teach xpoll() to measure time if interrupted, and wait for what's left. --- lib/net.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/net.c') diff --git a/lib/net.c b/lib/net.c index 4467f1fd..346d17e9 100644 --- a/lib/net.c +++ b/lib/net.c @@ -67,13 +67,16 @@ int xbind(struct addrinfo *ai) int xpoll(struct pollfd *fds, int nfds, int timeout) { int i; + long long now, then = timeout>0 ? millitime() : 0; for (;;) { - if (0>(i = poll(fds, nfds, timeout))) { - if (toys.signal) return i; - if (errno != EINTR && errno != ENOMEM) perror_exit("xpoll"); - else if (timeout>0) timeout--; - } else return i; + if (0<=(i = poll(fds, nfds, timeout)) || toys.signal) return i; + if (errno != EINTR && errno != ENOMEM) perror_exit("xpoll"); + else { + now = millitime(); + timeout -= now-then; + then = now; + } } } -- cgit v1.2.3