[commit: ghc] master: base: Fix fdReady() potentially running forever for Windows Char devices. (826c3b1)
git at git.haskell.org
git at git.haskell.org
Tue Sep 19 21:55:25 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/826c3b11780abcb74e5aba987e16369d69ac79a5/ghc
>---------------------------------------------------------------
commit 826c3b11780abcb74e5aba987e16369d69ac79a5
Author: Niklas Hambüchen <mail at nh2.me>
Date: Tue Sep 19 15:10:31 2017 -0400
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
>---------------------------------------------------------------
826c3b11780abcb74e5aba987e16369d69ac79a5
libraries/base/cbits/inputReady.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/libraries/base/cbits/inputReady.c b/libraries/base/cbits/inputReady.c
index 14f1c54..ab2a1c2 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;
}
}
More information about the ghc-commits
mailing list