summaryrefslogtreecommitdiff
path: root/ghc/lib/std/cbits/openFile.c
diff options
context:
space:
mode:
authorsimonmar <unknown>1999-09-16 13:14:43 +0000
committersimonmar <unknown>1999-09-16 13:14:43 +0000
commit6986b2b2439ce264df153878374f70cee54ef100 (patch)
tree07e1b667f51039b2ee9a2c3859119a23e5afa571 /ghc/lib/std/cbits/openFile.c
parentcadc82fc0a7a1e640bb04842769ca337dedb8c70 (diff)
downloadhaskell-6986b2b2439ce264df153878374f70cee54ef100.tar.gz
[project @ 1999-09-16 13:14:38 by simonmar]
Cleanup of non-blocking I/O - file descriptors are now always set to non-blocking mode. - we don't do an inputReady operation on descriptors before attempting to read from them any more. - the non-blocking flag on Handles has gone. - the {set,clear}[Conn]NonBlockingFlag() functions have gone. - the socket operations have been made to work properly with threads: accept is now non-blocking (it does a threadWaitRead instead of blocking), and the file descriptors returned by accept are set to non-blocking mode. Win32 will need some adjustments, no doubt.
Diffstat (limited to 'ghc/lib/std/cbits/openFile.c')
-rw-r--r--ghc/lib/std/cbits/openFile.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/ghc/lib/std/cbits/openFile.c b/ghc/lib/std/cbits/openFile.c
index 7d3b217ad2..5f24491fb6 100644
--- a/ghc/lib/std/cbits/openFile.c
+++ b/ghc/lib/std/cbits/openFile.c
@@ -1,7 +1,7 @@
/*
* (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
*
- * $Id: openFile.c,v 1.6 1999/02/04 12:13:15 sof Exp $
+ * $Id: openFile.c,v 1.7 1999/09/16 13:14:43 simonmar Exp $
*
* openFile Runtime Support
*/
@@ -40,6 +40,7 @@ StgInt flags;
StgInt rd;
{
IOFileObject* fo;
+ long fd_flags;
if ((fo = malloc(sizeof(IOFileObject))) == NULL)
return NULL;
@@ -49,7 +50,12 @@ StgInt rd;
fo->bufRPtr = 0;
fo->flags = flags | FILEOBJ_STD | ( rd ? FILEOBJ_READ : FILEOBJ_WRITE);
fo->connectedTo = NULL;
- return fo;
+
+ /* set the non-blocking flag on this file descriptor */
+ fd_flags = fcntl(fd, F_GETFL);
+ fcntl(fd, F_SETFL, fd_flags | O_NONBLOCK);
+
+ return fo;
}
#define OPENFILE_APPEND 0
@@ -79,19 +85,19 @@ StgInt flags;
switch (how) {
case OPENFILE_APPEND:
- oflags = O_WRONLY | O_NOCTTY | O_APPEND;
+ oflags = O_NONBLOCK | O_WRONLY | O_NOCTTY | O_APPEND;
for_writing = 1;
break;
case OPENFILE_WRITE:
- oflags = O_WRONLY | O_NOCTTY;
+ oflags = O_NONBLOCK | O_WRONLY | O_NOCTTY;
for_writing = 1;
break;
case OPENFILE_READ_ONLY:
- oflags = O_RDONLY | O_NOCTTY;
+ oflags = O_NONBLOCK | O_RDONLY | O_NOCTTY;
for_writing = 0;
break;
case OPENFILE_READ_WRITE:
- oflags = O_RDWR | O_NOCTTY;
+ oflags = O_NONBLOCK | O_RDWR | O_NOCTTY;
for_writing = 1;
break;
default: