Skip to content

Commit 68a8e31

Browse files
committed
Merge 'poll_inftim' into HEAD
This was originally 'pull request #330 from ethomson/poll_inftim' in msysgit/git. poll: honor the timeout on Win32 Signed-off-by: Johannes Schindelin <[email protected]>
2 parents d002525 + 1d99025 commit 68a8e31

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

compat/poll/poll.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
446446
static HANDLE hEvent;
447447
WSANETWORKEVENTS ev;
448448
HANDLE h, handle_array[FD_SETSIZE + 2];
449-
DWORD ret, wait_timeout, nhandles;
449+
DWORD ret, wait_timeout, nhandles, start = 0, elapsed, orig_timeout = 0;
450450
fd_set rfds, wfds, xfds;
451451
BOOL poll_again;
452452
MSG msg;
@@ -459,6 +459,12 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
459459
return -1;
460460
}
461461

462+
if (timeout != INFTIM)
463+
{
464+
orig_timeout = timeout;
465+
start = GetTickCount();
466+
}
467+
462468
if (!hEvent)
463469
hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
464470

@@ -603,7 +609,13 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
603609
rc++;
604610
}
605611

606-
if (!rc && timeout == INFTIM)
612+
if (!rc && orig_timeout && timeout != INFTIM)
613+
{
614+
elapsed = GetTickCount() - start;
615+
timeout = elapsed >= orig_timeout ? 0 : orig_timeout - elapsed;
616+
}
617+
618+
if (!rc && timeout)
607619
{
608620
SleepEx (1, TRUE);
609621
goto restart;

0 commit comments

Comments
 (0)