summaryrefslogtreecommitdiff
path: root/libraries/base/cbits/inputReady.c
diff options
context:
space:
mode:
authorsimonmar <unknown>2005-01-18 15:08:39 +0000
committersimonmar <unknown>2005-01-18 15:08:39 +0000
commit94fee9e70c27c9fff8f5d20b1556f748a1b7c92b (patch)
tree157ca5ce34104610964fdf05a27da65df4ee4fa7 /libraries/base/cbits/inputReady.c
parent33197cc6c185c3f270e19f77ab3b6e7911b99a0a (diff)
downloadhaskell-94fee9e70c27c9fff8f5d20b1556f748a1b7c92b.tar.gz
[project @ 2005-01-18 15:08:39 by simonmar]
Win32: attempt to make inputReady() work on pipes too. Fixes bug #995658.
Diffstat (limited to 'libraries/base/cbits/inputReady.c')
-rw-r--r--libraries/base/cbits/inputReady.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/libraries/base/cbits/inputReady.c b/libraries/base/cbits/inputReady.c
index 30e140b89c..a86f961d5e 100644
--- a/libraries/base/cbits/inputReady.c
+++ b/libraries/base/cbits/inputReady.c
@@ -49,7 +49,32 @@ inputReady(int fd, int msecs, int isSock)
else {
DWORD rc;
HANDLE hFile = (HANDLE)_get_osfhandle(fd);
-
+ DWORD avail;
+
+ // WaitForMultipleObjects() works for Console input, but it
+ // doesn't work for pipes (it always returns WAIT_OBJECT_0
+ // even when no data is available). There doesn't seem to be
+ // an easy way to distinguish the two kinds of HANDLE, so we
+ // try to detect pipe input first, and if that fails we try
+ // WaitForMultipleObjects().
+ //
+ rc = PeekNamedPipe( hFile, NULL, 0, NULL, &avail, NULL );
+ if (rc != 0) {
+ if (avail != 0) {
+ return 1;
+ } else {
+ return 0;
+ }
+ } else {
+ rc = GetLastError();
+ if (rc == ERROR_BROKEN_PIPE) {
+ return 1; // this is probably what we want
+ }
+ if (rc != ERROR_INVALID_HANDLE) {
+ return -1;
+ }
+ }
+
rc = WaitForMultipleObjects( 1,
&hFile,
TRUE, /* wait all */