Commit 826c3b11 authored by Niklas Hambüchen's avatar Niklas Hambüchen Committed by Ben Gamari

base: Fix fdReady() potentially running forever for Windows Char devices.

Reviewers: bgamari, austin, hvr

Reviewed By: bgamari

Subscribers: rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D3955
parent c2a1fa7a
......@@ -102,6 +102,8 @@ fdReady(int fd, int write, int msecs, int isSock)
HANDLE hFile = (HANDLE)_get_osfhandle(fd);
DWORD avail;
Time remaining = MSToTime(msecs);
switch (GetFileType(hFile)) {
case FILE_TYPE_CHAR:
......@@ -119,7 +121,11 @@ fdReady(int fd, int write, int msecs, int isSock)
while (1) // keep trying until we find a real key event
{
rc = WaitForSingleObject( hFile, msecs );
// WaitForSingleObject takes an unsigned number,
// `remaining` can be negative. Wait 0 if so.
DWORD wait_ms = (DWORD) max(0, TimeToMS(remaining));
rc = WaitForSingleObject( hFile, wait_ms );
switch (rc) {
case WAIT_TIMEOUT: return 0;
case WAIT_OBJECT_0: break;
......@@ -167,6 +173,9 @@ fdReady(int fd, int write, int msecs, int isSock)
}
}
}
Time now = getProcessElapsedTime();
remaining = endTime - now;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment