Skip to content

Commit ec852fb

Browse files
author
Git for Windows Build Agent
committed
Merge pull request #1003 from shoelzer/master
poll: Use GetTickCount64 to avoid wraparound issues
2 parents ea0d3b1 + fa4fcce commit ec852fb

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

compat/poll/poll.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,20 @@ win32_compute_revents_socket (SOCKET h, int sought, long lNetworkEvents)
267267
return happened;
268268
}
269269

270+
#include <windows.h>
271+
#include "compat/win32/lazyload.h"
272+
273+
static ULONGLONG CompatGetTickCount64(void)
274+
{
275+
DECLARE_PROC_ADDR(kernel32.dll, ULONGLONG, GetTickCount64, void);
276+
277+
if (!INIT_PROC_ADDR(GetTickCount64))
278+
return (ULONGLONG)GetTickCount();
279+
280+
return GetTickCount64();
281+
}
282+
#define GetTickCount64 CompatGetTickCount64
283+
270284
#else /* !MinGW */
271285

272286
/* Convert select(2) returned fd_sets into poll(2) revents values. */
@@ -450,7 +464,8 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
450464
static HANDLE hEvent;
451465
WSANETWORKEVENTS ev;
452466
HANDLE h, handle_array[FD_SETSIZE + 2];
453-
DWORD ret, wait_timeout, nhandles, start = 0, elapsed, orig_timeout = 0;
467+
DWORD ret, wait_timeout, nhandles, elapsed, orig_timeout = 0;
468+
ULONGLONG start = 0;
454469
fd_set rfds, wfds, xfds;
455470
BOOL poll_again;
456471
MSG msg;
@@ -466,7 +481,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
466481
if (timeout != INFTIM)
467482
{
468483
orig_timeout = timeout;
469-
start = GetTickCount();
484+
start = GetTickCount64();
470485
}
471486

472487
if (!hEvent)
@@ -615,7 +630,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
615630

616631
if (!rc && orig_timeout && timeout != INFTIM)
617632
{
618-
elapsed = GetTickCount() - start;
633+
elapsed = (DWORD)(GetTickCount64() - start);
619634
timeout = elapsed >= orig_timeout ? 0 : orig_timeout - elapsed;
620635
}
621636

0 commit comments

Comments
 (0)