changeset 196:928e1de0b626

- Fixed a double close of file descriptors.
author jcid
date Tue, 29 Apr 2008 16:49:40 +0200
parents 890bb568427b
children 04b72811e28f
files src/IO/IO.c src/IO/IO.h
diffstat 2 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/IO/IO.c	Sun Apr 27 18:18:14 2008 +0200
+++ b/src/IO/IO.c	Tue Apr 29 16:49:40 2008 +0200
@@ -129,17 +129,25 @@
 /*
  * Close an open FD, and remove io controls.
  * (This function can be used for Close and Abort operations)
+ * BUG: there's a race condition for Abort. The file descriptor is closed
+ * twice, and it could be reused for something else in between. It's simple
+ * to fix, but it'd be better to design a canonical way to Abort the CCC.
  */
 static void IO_close_fd(IOData_t *io, int CloseCode)
 {
    int st;
 
+   _MSG("====> begin IO close (%d) Key=%d CloseCode=%d Flags=%d ",
+       io->FD, io->Key, CloseCode, io->Flags);
+
    /* With HTTP, if we close the writing part, the reading one also gets
     * closed! (other clients may set 'IOFlag_ForceClose') */
    if ((io->Flags & IOFlag_ForceClose) || (CloseCode == IO_StopRdWr)) {
       do
          st = close(io->FD);
       while (st < 0 && errno == EINTR);
+   } else {
+      _MSG(" NOT CLOSING ");
    }
    /* Remove this IOData_t reference, from our ValidIOs list
     * We don't deallocate it here, just remove from the list.*/
@@ -147,6 +155,7 @@
 
    /* Stop the polling on this FD */
    a_IOwatch_remove_fd(io->FD, io->events);
+   _MSG(" end IO close (%d) <=====\n", io->FD);
 }
 
 /*
@@ -358,7 +367,7 @@
                MSG_WARN(" \"%s\"\n", dStr_printable(io->Buf, 2048));
             }
             /* close FD, remove from ValidIOs and remove its watch */
-            IO_close_fd(io, IO_StopRdWr);
+            IO_close_fd(io, Op == OpEnd ? IO_StopWr : IO_StopRdWr);
             IO_free(io);
             dFree(Info);
             break;
--- a/src/IO/IO.h	Sun Apr 27 18:18:14 2008 +0200
+++ b/src/IO/IO.h	Tue Apr 29 16:49:40 2008 +0200
@@ -17,7 +17,7 @@
 #define IOAbort  3
 
 /*
- * IO Flags (unused)
+ * IO Flags
  */
 #define IOFlag_ForceClose  (1 << 1)
 #define IOFlag_SingleWrite (1 << 2)