[NPFS]
authorCameron Gutman <aicommander@gmail.com>
Thu, 27 May 2010 23:52:32 +0000 (23:52 +0000)
committerCameron Gutman <aicommander@gmail.com>
Thu, 27 May 2010 23:52:32 +0000 (23:52 +0000)
- Partially revert r47370 and apply a better patch
- Change ReadEvent and WriteEvent to notification events because we reset those events manually when we run out of buffer space

svn path=/trunk/; revision=47375

reactos/drivers/filesystems/npfs/create.c
reactos/drivers/filesystems/npfs/rw.c

index 86209bd..2eb0aad 100644 (file)
@@ -205,8 +205,8 @@ NpfsCreate(PDEVICE_OBJECT DeviceObject,
     ClientCcb->MaxDataLength = Fcb->OutboundQuota;
     ExInitializeFastMutex(&ClientCcb->DataListLock);
     KeInitializeEvent(&ClientCcb->ConnectEvent, SynchronizationEvent, FALSE);
-    KeInitializeEvent(&ClientCcb->ReadEvent, SynchronizationEvent, FALSE);
-    KeInitializeEvent(&ClientCcb->WriteEvent, SynchronizationEvent, FALSE);
+    KeInitializeEvent(&ClientCcb->ReadEvent, NotificationEvent, FALSE);
+    KeInitializeEvent(&ClientCcb->WriteEvent, NotificationEvent, FALSE);
 
 
     /*
@@ -540,8 +540,8 @@ NpfsCreateNamedPipe(PDEVICE_OBJECT DeviceObject,
     DPRINT("CCB: %p\n", Ccb);
 
     KeInitializeEvent(&Ccb->ConnectEvent, SynchronizationEvent, FALSE);
-    KeInitializeEvent(&Ccb->ReadEvent, SynchronizationEvent, FALSE);
-    KeInitializeEvent(&Ccb->WriteEvent, SynchronizationEvent, FALSE);
+    KeInitializeEvent(&Ccb->ReadEvent, NotificationEvent, FALSE);
+    KeInitializeEvent(&Ccb->WriteEvent, NotificationEvent, FALSE);
 
     KeLockMutex(&Fcb->CcbListLock);
     InsertTailList(&Fcb->ServerCcbListHead, &Ccb->CcbListEntry);
@@ -619,7 +619,6 @@ NpfsCleanup(PDEVICE_OBJECT DeviceObject,
             ExAcquireFastMutex(&OtherSide->DataListLock);
             ExAcquireFastMutex(&Ccb->DataListLock);
         }
-        OtherSide->PipeState = FILE_PIPE_CLOSING_STATE;
         OtherSide->OtherSide = NULL;
         /*
         * Signaling the write event. If is possible that an other
@@ -745,7 +744,6 @@ NpfsClose(PDEVICE_OBJECT DeviceObject,
     /* Disconnect the pipes */
     if (Ccb->OtherSide)
     {
-        Ccb->OtherSide->PipeState = FILE_PIPE_CLOSING_STATE;
         Ccb->OtherSide->OtherSide = NULL;
         Ccb->OtherSide = NULL;
     }
index 4c83f5c..f3f02bd 100644 (file)
@@ -331,11 +331,8 @@ NpfsRead(IN PDEVICE_OBJECT DeviceObject,
 
     if ((Ccb->OtherSide == NULL) && (Ccb->ReadDataAvailable == 0))
     {
-        if (Ccb->PipeState == FILE_PIPE_CLOSING_STATE)
-        {
-            DPRINT("File pipe broken\n");
+        if (Ccb->PipeState == FILE_PIPE_CONNECTED_STATE)
             Status = STATUS_PIPE_BROKEN;
-        }
         else if (Ccb->PipeState == FILE_PIPE_LISTENING_STATE)
             Status = STATUS_PIPE_LISTENING;
         else if (Ccb->PipeState == FILE_PIPE_DISCONNECTED_STATE)
@@ -443,7 +440,7 @@ NpfsRead(IN PDEVICE_OBJECT DeviceObject,
                 {
                     break;
                 }
-                if ((Ccb->PipeState != FILE_PIPE_CONNECTED_STATE) && (Ccb->ReadDataAvailable == 0))
+                if (((Ccb->PipeState != FILE_PIPE_CONNECTED_STATE) || (!Ccb->OtherSide)) && (Ccb->ReadDataAvailable == 0))
                 {
                     DPRINT("PipeState: %x\n", Ccb->PipeState);
                     Status = STATUS_PIPE_BROKEN;
@@ -800,13 +797,13 @@ NpfsWrite(PDEVICE_OBJECT DeviceObject,
     {
         if ((ReaderCcb->WriteQuotaAvailable == 0))
         {
-            KeSetEvent(&ReaderCcb->ReadEvent, IO_NO_INCREMENT, FALSE);
-            if (Ccb->PipeState != FILE_PIPE_CONNECTED_STATE)
+            if (Ccb->PipeState != FILE_PIPE_CONNECTED_STATE || !Ccb->OtherSide)
             {
                 Status = STATUS_PIPE_BROKEN;
                 ExReleaseFastMutex(&ReaderCcb->DataListLock);
                 goto done;
             }
+            KeSetEvent(&ReaderCcb->ReadEvent, IO_NO_INCREMENT, FALSE);
             ExReleaseFastMutex(&ReaderCcb->DataListLock);
 
             DPRINT("Write Waiting for buffer space (%S)\n", Fcb->PipeName.Buffer);
@@ -830,20 +827,15 @@ NpfsWrite(PDEVICE_OBJECT DeviceObject,
             * It's possible that the event was signaled because the
             * other side of pipe was closed.
             */
-            if (Ccb->PipeState != FILE_PIPE_CONNECTED_STATE)
+            if (Ccb->PipeState != FILE_PIPE_CONNECTED_STATE || !Ccb->OtherSide)
             {
                 DPRINT("PipeState: %x\n", Ccb->PipeState);
                 Status = STATUS_PIPE_BROKEN;
                 goto done;
             }
             /* Check that the pipe has not been closed */
-            if (ReaderCcb->PipeState != FILE_PIPE_CONNECTED_STATE)
+            if (ReaderCcb->PipeState != FILE_PIPE_CONNECTED_STATE || !ReaderCcb->OtherSide)
             {
-                /* If the other side is valid, fire event */
-                if (Ccb)
-                {
-                    KeResetEvent(&Ccb->WriteEvent);
-                }
                 Status = STATUS_PIPE_BROKEN;
                 goto done;
             }