[project @ 1999-11-05 15:25:49 by simonmar]
authorsimonmar <unknown>
Fri, 5 Nov 1999 15:25:49 +0000 (15:25 +0000)
committersimonmar <unknown>
Fri, 5 Nov 1999 15:25:49 +0000 (15:25 +0000)
Handle potentially blocking writes (yes, I've seen one :) Or rather,
its footprint: unfortunately, the error message didn't appear because
writes to stderr were returning EAGAIN etc. etc., see accompanying
commit to writeError.c.)

ghc/lib/std/cbits/writeFile.c

index 0b459f3..0c2f78f 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
  *
- * $Id: writeFile.c,v 1.8 1999/09/16 13:14:43 simonmar Exp $
+ * $Id: writeFile.c,v 1.9 1999/11/05 15:25:49 simonmar Exp $
  *
  * hPutStr Runtime Support
  */
@@ -62,13 +62,19 @@ StgInt bytes;
 #else
                 write(fo->fd, pBuf, bytes))) < bytes) {
 #endif
-       if (errno != EINTR) {
+        if ( count == -1 && errno == EAGAIN) {
+            errno = 0;
+            return FILEOBJ_BLOCKED_WRITE;
+        }
+       else if ( count == -1 && errno != EINTR ) {
            cvtErrno();
            stdErrno();
            return -1;
        }
-       bytes -= count;
-       pBuf  += count;
+        else {
+           bytes -= count;
+           pBuf  += count;
+        }
     }
     /* Signal that we've emptied the buffer */
     fo->bufWPtr=0;