diff --git a/src/unix/kqueue.c b/src/unix/kqueue.c index b78242d3be4..85183c88f1d 100644 --- a/src/unix/kqueue.c +++ b/src/unix/kqueue.c @@ -260,9 +260,6 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { ARRAY_SIZE(events), timeout == -1 ? NULL : &spec); - if (nfds == -1) - assert(errno == EINTR); - if (pset != NULL) pthread_sigmask(SIG_UNBLOCK, pset, NULL); @@ -272,6 +269,12 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { */ uv__update_time(loop); + if (nfds == -1) + assert(errno == EINTR); + else if (nfds == 0) + /* Unlimited timeout should only return with events or signal. */ + assert(timeout != -1); + if (nfds == 0 || nfds == -1) { /* If kqueue is empty or interrupted, we might still have children ready * to reap immediately. */ @@ -285,13 +288,13 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { if (reset_timeout != 0) { timeout = user_timeout; reset_timeout = 0; - } else if (nfds == 0) { - /* Reached the user timeout value. */ - assert(timeout != -1); - return; } - /* Interrupted by a signal. Update timeout and poll again. */ + /* If nfds == 0 then we may have been inside the system call for longer + * than |timeout| milliseconds so we need to update the timestamp to + * avoid drift. + * If nfds == -1 then it was interrupted by a signal. Update timeout and + * poll again. */ goto update_timeout; } diff --git a/src/unix/linux.c b/src/unix/linux.c index 65fb847f65b..b4cc548000c 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -1370,42 +1370,23 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { */ SAVE_ERRNO(uv__update_time(loop)); - if (nfds == 0) { + if (nfds == -1) + assert(errno == EINTR); + else if (nfds == 0) + /* Unlimited timeout should only return with events or signal. */ assert(timeout != -1); + if (nfds == 0 || nfds == -1) { if (reset_timeout != 0) { timeout = user_timeout; reset_timeout = 0; } - if (timeout == -1) - continue; - - if (timeout == 0) - break; - - /* We may have been inside the system call for longer than |timeout| - * milliseconds so we need to update the timestamp to avoid drift. - */ - goto update_timeout; - } - - if (nfds == -1) { - if (errno != EINTR) - abort(); - - if (reset_timeout != 0) { - timeout = user_timeout; - reset_timeout = 0; - } - - if (timeout == -1) - continue; - - if (timeout == 0) - break; - - /* Interrupted by a signal. Update timeout and poll again. */ + /* If nfds == 0 then we may have been inside the system call for longer + * than |timeout| milliseconds so we need to update the timestamp to + * avoid drift. + * If nfds == -1 then it was interrupted by a signal. Update timeout and + * poll again. */ goto update_timeout; } @@ -1515,13 +1496,13 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { break; } +update_timeout: if (timeout == 0) break; if (timeout == -1) continue; -update_timeout: assert(timeout > 0); real_timeout -= (loop->time - base);