aboutsummaryrefslogtreecommitdiff
path: root/lib/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/net.c')
-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;
+ }
}
}