diff options
Diffstat (limited to 'compat/poll/poll.c')
-rw-r--r-- | compat/poll/poll.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/compat/poll/poll.c b/compat/poll/poll.c index 31163f2ae7..b10adc780f 100644 --- a/compat/poll/poll.c +++ b/compat/poll/poll.c @@ -76,7 +76,7 @@ #ifdef WIN32_NATIVE -#define IsConsoleHandle(h) (((long) (h) & 3) == 3) +#define IsConsoleHandle(h) (((long) (intptr_t) (h) & 3) == 3) static BOOL IsSocketHandle (HANDLE h) @@ -446,7 +446,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout) static HANDLE hEvent; WSANETWORKEVENTS ev; HANDLE h, handle_array[FD_SETSIZE + 2]; - DWORD ret, wait_timeout, nhandles; + DWORD ret, wait_timeout, nhandles, start = 0, elapsed, orig_timeout = 0; fd_set rfds, wfds, xfds; BOOL poll_again; MSG msg; @@ -459,6 +459,12 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout) return -1; } + if (timeout != INFTIM) + { + orig_timeout = timeout; + start = GetTickCount(); + } + if (!hEvent) hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); @@ -603,9 +609,15 @@ restart: rc++; } - if (!rc && timeout == INFTIM) + if (!rc && orig_timeout && timeout != INFTIM) + { + elapsed = GetTickCount() - start; + timeout = elapsed >= orig_timeout ? 0 : orig_timeout - elapsed; + } + + if (!rc && timeout) { - SwitchToThread(); + SleepEx (1, TRUE); goto restart; } |