[ros-diffs] [cgutman] 40200: - Fix several cancellation and socket shutdown issues: - Don't call DestroySocket if FCB->State == SOCKET_STATE_CLOSED because the FCB is already being destroyed (Irp->Cancel checks hid this bug) - Remove the Irp->Cancel checks (hacks) - Only return early if we can't cancel an IRP - Add an FCB->State check in StreamSocketConnectComplete - Store the failure status in the IRP

cgutman at svn.reactos.org cgutman at svn.reactos.org
Tue Mar 24 03:01:47 CET 2009


Author: cgutman
Date: Tue Mar 24 05:01:46 2009
New Revision: 40200

URL: http://svn.reactos.org/svn/reactos?rev=40200&view=rev
Log:
 - Fix several cancellation and socket shutdown issues:
 - Don't call DestroySocket if FCB->State == SOCKET_STATE_CLOSED because the FCB is already being destroyed (Irp->Cancel checks hid this bug)
 - Remove the Irp->Cancel checks (hacks)
 - Only return early if we can't cancel an IRP
 - Add an FCB->State check in StreamSocketConnectComplete
 - Store the failure status in the IRP

Modified:
    trunk/reactos/drivers/network/afd/afd/connect.c
    trunk/reactos/drivers/network/afd/afd/listen.c
    trunk/reactos/drivers/network/afd/afd/main.c
    trunk/reactos/drivers/network/afd/afd/read.c
    trunk/reactos/drivers/network/afd/afd/write.c

Modified: trunk/reactos/drivers/network/afd/afd/connect.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/afd/connect.c?rev=40200&r1=40199&r2=40200&view=diff
==============================================================================
--- trunk/reactos/drivers/network/afd/afd/connect.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/afd/afd/connect.c [iso-8859-1] Tue Mar 24 05:01:46 2009
@@ -84,16 +84,22 @@
 
     /* I was wrong about this before as we can have pending writes to a not
      * yet connected socket */
-    if( !SocketAcquireStateLock( FCB ) ) return STATUS_FILE_CLOSED;
+    if( !SocketAcquireStateLock( FCB ) ) {
+        Irp->IoStatus.Status = STATUS_FILE_CLOSED;
+        Irp->IoStatus.Information = 0;
+        return STATUS_FILE_CLOSED;
+    }
 
     AFD_DbgPrint(MID_TRACE,("Irp->IoStatus.Status = %x\n",
 			    Irp->IoStatus.Status));
 
     FCB->ConnectIrp.InFlightRequest = NULL;
 
-    if( Irp->Cancel ) {
-        SocketStateUnlock( FCB );
-	return STATUS_CANCELLED;
+    if( FCB->State == SOCKET_STATE_CLOSED ) {
+        Irp->IoStatus.Status = STATUS_FILE_CLOSED;
+        Irp->IoStatus.Information = 0;
+	SocketStateUnlock( FCB );
+	return STATUS_FILE_CLOSED;
     }
 
     if( NT_SUCCESS(Irp->IoStatus.Status) ) {
@@ -123,6 +129,8 @@
 	Status = MakeSocketIntoConnection( FCB );
 
 	if( !NT_SUCCESS(Status) ) {
+            Irp->IoStatus.Status = Status;
+            Irp->IoStatus.Information = 0;
 	    SocketStateUnlock( FCB );
 	    return Status;
 	}
@@ -141,6 +149,12 @@
 
 	if( Status == STATUS_PENDING )
 	    Status = STATUS_SUCCESS;
+    }
+
+    if (!NT_SUCCESS(Status))
+    {
+        Irp->IoStatus.Status = Status;
+        Irp->IoStatus.Information = 0;
     }
 
     SocketStateUnlock( FCB );

Modified: trunk/reactos/drivers/network/afd/afd/listen.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/afd/listen.c?rev=40200&r1=40199&r2=40200&view=diff
==============================================================================
--- trunk/reactos/drivers/network/afd/afd/listen.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/afd/afd/listen.c [iso-8859-1] Tue Mar 24 05:01:46 2009
@@ -112,18 +112,10 @@
 
     FCB->ListenIrp.InFlightRequest = NULL;
 
-    if( Irp->Cancel ) {
-        Irp->IoStatus.Status = STATUS_CANCELLED;
-        Irp->IoStatus.Information = 0;
-        SocketStateUnlock( FCB );
-	return STATUS_CANCELLED;
-    }
-
     if( FCB->State == SOCKET_STATE_CLOSED ) {
         Irp->IoStatus.Status = STATUS_FILE_CLOSED;
         Irp->IoStatus.Information = 0;
 	SocketStateUnlock( FCB );
-	DestroySocket( FCB );
 	return STATUS_FILE_CLOSED;
     }
 

Modified: trunk/reactos/drivers/network/afd/afd/main.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/afd/main.c?rev=40200&r1=40199&r2=40200&view=diff
==============================================================================
--- trunk/reactos/drivers/network/afd/afd/main.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/afd/afd/main.c [iso-8859-1] Tue Mar 24 05:01:46 2009
@@ -180,36 +180,20 @@
     InFlightRequest[2] = &FCB->SendIrp;
     InFlightRequest[3] = &FCB->ConnectIrp;
 
-    /* Return early here because we might be called in the mean time. */
-    if( FCB->Critical ||
-	FCB->ListenIrp.InFlightRequest ||
-	FCB->ReceiveIrp.InFlightRequest ||
-	FCB->SendIrp.InFlightRequest ||
-	FCB->ConnectIrp.InFlightRequest ) {
-	AFD_DbgPrint(MIN_TRACE,("Leaving socket alive (%x %x %x %x)\n",
-				FCB->ListenIrp.InFlightRequest,
-				FCB->ReceiveIrp.InFlightRequest,
-				FCB->SendIrp.InFlightRequest,
-				FCB->ConnectIrp.InFlightRequest));
-        ReturnEarly = TRUE;
-    }
-
-    /* After PoolReeval, this FCB should not be involved in any outstanding
-     * poll requests */
-
     /* Cancel our pending requests */
     for( i = 0; i < IN_FLIGHT_REQUESTS; i++ ) {
 	if( InFlightRequest[i]->InFlightRequest ) {
 	    AFD_DbgPrint(MID_TRACE,("Cancelling in flight irp %d (%x)\n",
 				    i, InFlightRequest[i]->InFlightRequest));
-	    IoCancelIrp(InFlightRequest[i]->InFlightRequest);
-	    InFlightRequest[i]->InFlightRequest = NULL;
+            if (!IoCancelIrp(InFlightRequest[i]->InFlightRequest))
+                ReturnEarly = TRUE;
 	}
     }
 
     SocketStateUnlock( FCB );
 
-    if( ReturnEarly ) return;
+    if( ReturnEarly )
+        return;
 
     if( FCB->Recv.Window )
 	ExFreePool( FCB->Recv.Window );

Modified: trunk/reactos/drivers/network/afd/afd/read.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/afd/read.c?rev=40200&r1=40199&r2=40200&view=diff
==============================================================================
--- trunk/reactos/drivers/network/afd/afd/read.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/afd/afd/read.c [iso-8859-1] Tue Mar 24 05:01:46 2009
@@ -238,13 +238,6 @@
 
     FCB->ReceiveIrp.InFlightRequest = NULL;
 
-    if( Irp->Cancel ) {
-        Irp->IoStatus.Status = STATUS_CANCELLED;
-        Irp->IoStatus.Information = 0;
-        SocketStateUnlock( FCB );
-		return STATUS_CANCELLED;
-    }
-
     FCB->Recv.Content = Irp->IoStatus.Information;
     FCB->Recv.BytesUsed = 0;
 
@@ -253,7 +246,6 @@
         Irp->IoStatus.Status = STATUS_FILE_CLOSED;
         Irp->IoStatus.Information = 0;
 		SocketStateUnlock( FCB );
-		DestroySocket( FCB );
 		return STATUS_FILE_CLOSED;
     } else if( FCB->State == SOCKET_STATE_LISTENING ) {
         AFD_DbgPrint(MIN_TRACE,("!!! LISTENER GOT A RECEIVE COMPLETE !!!\n"));
@@ -468,18 +460,10 @@
 
     FCB->ReceiveIrp.InFlightRequest = NULL;
 
-    if( Irp->IoStatus.Status == STATUS_CANCELLED ) {
-        Irp->IoStatus.Status = STATUS_CANCELLED;
-        Irp->IoStatus.Information = 0;
-        SocketStateUnlock( FCB );
-		return STATUS_CANCELLED;
-    }
-
     if( FCB->State == SOCKET_STATE_CLOSED ) {
         Irp->IoStatus.Status = STATUS_FILE_CLOSED;
         Irp->IoStatus.Information = 0;
 		SocketStateUnlock( FCB );
-		DestroySocket( FCB );
 		return STATUS_FILE_CLOSED;
     }
 

Modified: trunk/reactos/drivers/network/afd/afd/write.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/afd/write.c?rev=40200&r1=40199&r2=40200&view=diff
==============================================================================
--- trunk/reactos/drivers/network/afd/afd/write.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/afd/afd/write.c [iso-8859-1] Tue Mar 24 05:01:46 2009
@@ -49,18 +49,10 @@
     FCB->SendIrp.InFlightRequest = NULL;
     /* Request is not in flight any longer */
 
-    if( Irp->Cancel ) {
-        Irp->IoStatus.Status = STATUS_CANCELLED;
-        Irp->IoStatus.Information = 0;
-        SocketStateUnlock( FCB );
-	return STATUS_CANCELLED;
-    }
-
     if( FCB->State == SOCKET_STATE_CLOSED ) {
         Irp->IoStatus.Status = STATUS_FILE_CLOSED;
         Irp->IoStatus.Information = 0;
 	SocketStateUnlock( FCB );
-	DestroySocket( FCB );
 	return STATUS_FILE_CLOSED;
     }
 
@@ -189,13 +181,6 @@
     FCB->SendIrp.InFlightRequest = NULL;
     /* Request is not in flight any longer */
 
-    if( Irp->Cancel ) {
-        Irp->IoStatus.Status = STATUS_CANCELLED;
-        Irp->IoStatus.Information = 0;
-        SocketStateUnlock( FCB );
-	return STATUS_CANCELLED;
-    }
-
     FCB->PollState |= AFD_EVENT_SEND;
     PollReeval( FCB->DeviceExt, FCB->FileObject );
 
@@ -203,7 +188,6 @@
         Irp->IoStatus.Status = STATUS_FILE_CLOSED;
         Irp->IoStatus.Information = 0;
 	SocketStateUnlock( FCB );
-	DestroySocket( FCB );
 	return STATUS_FILE_CLOSED;
     }
 



More information about the Ros-diffs mailing list