Skip to content

Commit

Permalink
Merge 'poll_inftim' into HEAD
Browse files Browse the repository at this point in the history
This was originally 'pull request msysgit#330 from ethomson/poll_inftim' in
msysgit/git.

poll: honor the timeout on Win32

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Apr 29, 2015
2 parents dc43aa3 + 492f3c6 commit a4b0473
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions compat/poll/poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -603,7 +609,13 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
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)
{
SleepEx (1, TRUE);
goto restart;
Expand Down

0 comments on commit a4b0473

Please sign in to comment.