summaryrefslogtreecommitdiff
path: root/libraries/base/cbits
diff options
context:
space:
mode:
authorNiklas Hambüchen <mail@nh2.me>2017-09-19 15:10:31 -0400
committerBen Gamari <ben@smart-cactus.org>2017-09-19 15:58:45 -0400
commit826c3b11780abcb74e5aba987e16369d69ac79a5 (patch)
tree256258509e0fea23f36c38089a7aaca213927f56 /libraries/base/cbits
parentc2a1fa7aec426727be6df79f3db109183e42cfdc (diff)
downloadhaskell-826c3b11780abcb74e5aba987e16369d69ac79a5.tar.gz
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
Diffstat (limited to 'libraries/base/cbits')
-rw-r--r--libraries/base/cbits/inputReady.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/libraries/base/cbits/inputReady.c b/libraries/base/cbits/inputReady.c
index 14f1c546c2..ab2a1c2197 100644
--- a/libraries/base/cbits/inputReady.c
+++ b/libraries/base/cbits/inputReady.c
@@ -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;
}
}