diff options
author | Rob Landley <rob@landley.net> | 2019-01-18 08:31:12 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-01-18 08:31:12 -0600 |
commit | d5becb1a234d56fb107be7411d3692b572086733 (patch) | |
tree | 5c2db948da647f3920b0d7fd40c6f30316d395fb | |
parent | d775032eea8056a93a4a2758a112bdb4fd8764bf (diff) | |
download | toybox-d5becb1a234d56fb107be7411d3692b572086733.tar.gz |
Teach xpoll() to measure time if interrupted, and wait for what's left.
-rw-r--r-- | lib/net.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -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; + } } } |