aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--win32/poll.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/win32/poll.c b/win32/poll.c
index dd3b2d1cb..4b825c5cc 100644
--- a/win32/poll.c
+++ b/win32/poll.c
@@ -469,6 +469,9 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
469 MSG msg; 469 MSG msg;
470 int rc = 0; 470 int rc = 0;
471 nfds_t i; 471 nfds_t i;
472 DWORD real_timeout = 0;
473 int save_timeout = timeout;
474 clock_t tend = clock () + timeout;
472 475
473 if (nfd > INT_MAX || timeout < -1) 476 if (nfd > INT_MAX || timeout < -1)
474 { 477 {
@@ -480,6 +483,14 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
480 hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); 483 hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
481 484
482restart: 485restart:
486 /* How much is left to wait? */
487 timeout = save_timeout;
488 if (timeout != INFTIM)
489 {
490 clock_t now = clock ();
491 real_timeout = tend > now ? tend - now : 0;
492 }
493
483 handle_array[0] = hEvent; 494 handle_array[0] = hEvent;
484 nhandles = 1; 495 nhandles = 1;
485 FD_ZERO (&rfds); 496 FD_ZERO (&rfds);
@@ -620,7 +631,7 @@ restart:
620 rc++; 631 rc++;
621 } 632 }
622 633
623 if (!rc && timeout == INFTIM) 634 if (!rc && (save_timeout == INFTIM || (real_timeout != 0 && nhandles > 1)))
624 { 635 {
625 SleepEx (1, TRUE); 636 SleepEx (1, TRUE);
626 goto restart; 637 goto restart;