select() fixes around timeout expiry return value

This commit is contained in:
manojampalam 2016-03-07 22:46:21 -08:00
parent 682fac1587
commit ae2873e8f1
2 changed files with 63 additions and 72 deletions

View File

@ -15,8 +15,8 @@
* - any signals (errno = EINTR ) - TODO
* - any of the supplied events set
* - any APCs caused by IO completions
* - time out (errno = ETIMEOUT)
* - Returns 0 on IO completion and -1 on rest
* - time out
* - Returns 0 on IO completion, timeout -1 on rest
* if milli_seconds is 0, this function returns 0, its called with 0
* to execute any scheduled APCs
*/
@ -35,11 +35,7 @@ wait_for_any_event(HANDLE* events, int num_events, DWORD milli_seconds)
return 0;
}
else if (ret == WAIT_TIMEOUT) {
if (milli_seconds == 0)
return 0;
errno = ETIMEDOUT;
debug("ERROR: wait timed out");
return -1;
}
/* some other error*/
else {
@ -54,11 +50,7 @@ wait_for_any_event(HANDLE* events, int num_events, DWORD milli_seconds)
return 0;
}
else if (ret == 0) {
if (milli_seconds == 0)
return 0;
errno = ETIMEDOUT;
debug("ERROR: wait timed out");
return -1;
}
else { //some other error
errno = EOTHER;

View File

@ -534,6 +534,10 @@ w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* excep
}
}
/* timeout specified and both fields are 0 - polling mode*/
/* proceed with further wait if not in polling mode*/
if ((timeout == NULL) || (timeout_ms != 0))
/* wait for io if none is already ready */
while (out_ready_fds == 0) {
ticks_spent = GetTickCount64() - ticks_start;
@ -541,12 +545,13 @@ w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* excep
if (timeout != NULL) {
if (timeout_ms < ticks_spent) {
errno = ETIMEDOUT;
debug("select timing out");
return -1;
break;
}
time_rem = timeout_ms - (ticks_spent & 0xffffffff);
}
else
time_rem = INFINITE;
if (0 != wait_for_any_event(events, num_events, time_rem))
return -1;
@ -572,16 +577,10 @@ w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* excep
}
}
if (out_ready_fds == 0) {
if (timeout == 0) {
/* not timeout specified, return EAGAIN if none of fds are ready */
errno = EAGAIN;
return -1;
}
if (out_ready_fds == 0)
debug2("wait ended without any IO completion, looping again");
}
};
}
/* clear out fds that are not ready yet */
if (readfds)