diff options
author | Simon Marlow <simonmar@microsoft.com> | 2007-05-07 12:35:37 +0000 |
---|---|---|
committer | Simon Marlow <simonmar@microsoft.com> | 2007-05-07 12:35:37 +0000 |
commit | d8f90d7fb7ccd8ed7806ea8b61721104cc89a2b2 (patch) | |
tree | bc50c6c299cbd8a357347de3524c905f830c7d68 /libraries/base/cbits/inputReady.c | |
parent | c12da1c090bff457da5bf652a5cec22d75619c09 (diff) | |
download | haskell-d8f90d7fb7ccd8ed7806ea8b61721104cc89a2b2.tar.gz |
FIX: #724 (tee complains if used in a process started by ghc)
Now, we only set O_NONBLOCK on file descriptors that we create
ourselves. File descriptors that we inherit (stdin, stdout, stderr)
are kept in blocking mode. The way we deal with this differs between
the threaded and non-threaded runtimes:
- with -threaded, we just make a safe foreign call to read(), which
may block, but this is ok.
- without -threaded, we test the descriptor with select() before
attempting any I/O. This isn't completely safe - someone else
might read the data between the select() and the read() - but it's
a reasonable compromise and doesn't seem to measurably affect
performance.
Diffstat (limited to 'libraries/base/cbits/inputReady.c')
-rw-r--r-- | libraries/base/cbits/inputReady.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/libraries/base/cbits/inputReady.c b/libraries/base/cbits/inputReady.c index f827fe5def..f539110f19 100644 --- a/libraries/base/cbits/inputReady.c +++ b/libraries/base/cbits/inputReady.c @@ -14,7 +14,7 @@ * *character* from this file object without blocking?' */ int -inputReady(int fd, int msecs, int isSock) +fdReady(int fd, int write, int msecs, int isSock) { if #if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32) @@ -23,11 +23,16 @@ inputReady(int fd, int msecs, int isSock) ( 1 ) { #endif int maxfd, ready; - fd_set rfd; + fd_set rfd, wfd; struct timeval tv; FD_ZERO(&rfd); - FD_SET(fd, &rfd); + FD_ZERO(&wfd); + if (write) { + FD_SET(fd, &wfd); + } else { + FD_SET(fd, &rfd); + } /* select() will consider the descriptor set in the range of 0 to * (maxfd-1) @@ -36,7 +41,7 @@ inputReady(int fd, int msecs, int isSock) tv.tv_sec = msecs / 1000; tv.tv_usec = (msecs % 1000) * 1000; - while ((ready = select(maxfd, &rfd, NULL, NULL, &tv)) < 0 ) { + while ((ready = select(maxfd, &rfd, &wfd, NULL, &tv)) < 0 ) { if (errno != EINTR ) { return -1; } |