aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-01-18 08:31:12 -0600
committerRob Landley <rob@landley.net>2019-01-18 08:31:12 -0600
commitd5becb1a234d56fb107be7411d3692b572086733 (patch)
tree5c2db948da647f3920b0d7fd40c6f30316d395fb
parentd775032eea8056a93a4a2758a112bdb4fd8764bf (diff)
downloadtoybox-d5becb1a234d56fb107be7411d3692b572086733.tar.gz
Teach xpoll() to measure time if interrupted, and wait for what's left.
-rw-r--r--lib/net.c13
1 files changed, 8 insertions, 5 deletions
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;
+ }
}
}