Author: cgutman
Date: Sun Apr 5 11:08:47 2009
New Revision: 40366
URL:
http://svn.reactos.org/svn/reactos?rev=40366&view=rev
Log:
- Implement a DispatchCleanup routine and properly separate cleanup from close
Modified:
trunk/reactos/drivers/network/afd/afd/main.c
Modified: trunk/reactos/drivers/network/afd/afd/main.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/afd/ma…
==============================================================================
--- trunk/reactos/drivers/network/afd/afd/main.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/afd/afd/main.c [iso-8859-1] Sun Apr 5 11:08:47 2009
@@ -167,9 +167,8 @@
return Status;
}
-VOID DestroySocket( PAFD_FCB FCB ) {
+VOID CleanupSocket( PAFD_FCB FCB ) {
UINT i;
- BOOLEAN ReturnEarly = FALSE;
PAFD_IN_FLIGHT_REQUEST InFlightRequest[IN_FLIGHT_REQUESTS];
AFD_DbgPrint(MIN_TRACE,("Called (%x)\n", FCB));
@@ -188,46 +187,60 @@
if( InFlightRequest[i]->InFlightRequest ) {
AFD_DbgPrint(MID_TRACE,("Cancelling in flight irp %d (%x)\n",
i, InFlightRequest[i]->InFlightRequest));
- if (!IoCancelIrp(InFlightRequest[i]->InFlightRequest))
- ReturnEarly = TRUE;
+ IoCancelIrp(InFlightRequest[i]->InFlightRequest);
}
}
+ FCB->State = SOCKET_STATE_CREATED;
+
+ if( FCB->EventSelect ) {
+ ObDereferenceObject( FCB->EventSelect );
+ FCB->EventSelect = NULL;
+ }
+ if( FCB->Context ) {
+ ExFreePool( FCB->Context );
+ FCB->Context = NULL;
+ }
+ if( FCB->Recv.Window ) {
+ ExFreePool( FCB->Recv.Window );
+ FCB->Recv.Window = NULL;
+ }
+ if( FCB->Send.Window ) {
+ ExFreePool( FCB->Send.Window );
+ FCB->Send.Window = NULL;
+ }
+ if( FCB->AddressFrom ) {
+ ExFreePool( FCB->AddressFrom );
+ FCB->AddressFrom = NULL;
+ }
+ if( FCB->LocalAddress ) {
+ ExFreePool( FCB->LocalAddress );
+ FCB->LocalAddress = NULL;
+ }
+ if( FCB->RemoteAddress ) {
+ ExFreePool( FCB->RemoteAddress );
+ FCB->RemoteAddress = NULL;
+ }
+ if( FCB->Connection.Object ) {
+ NtClose(FCB->Connection.Handle);
+ ObDereferenceObject(FCB->Connection.Object);
+ FCB->Connection.Object = NULL;
+ }
+ if( FCB->AddressFile.Object ) {
+ NtClose(FCB->AddressFile.Handle);
+ ObDereferenceObject(FCB->AddressFile.Object);
+ FCB->AddressFile.Object = NULL;
+ }
+
SocketStateUnlock( FCB );
-
- if( ReturnEarly )
- return;
-
- if( FCB->Context )
- ExFreePool(FCB->Context);
- if( FCB->Recv.Window )
- ExFreePool( FCB->Recv.Window );
- if( FCB->Send.Window )
- ExFreePool( FCB->Send.Window );
- if( FCB->AddressFrom )
- ExFreePool( FCB->AddressFrom );
- if( FCB->LocalAddress )
- ExFreePool( FCB->LocalAddress );
- if( FCB->RemoteAddress )
- ExFreePool( FCB->RemoteAddress );
+}
+
+VOID DestroySocket( PAFD_FCB FCB ) {
if( FCB->TdiDeviceName.Buffer )
ExFreePool(FCB->TdiDeviceName.Buffer);
- if (FCB->Connection.Object)
- {
- NtClose(FCB->Connection.Handle);
- ObDereferenceObject(FCB->Connection.Object);
- }
- if (FCB->AddressFile.Object)
- {
- NtClose(FCB->AddressFile.Handle);
- ObDereferenceObject(FCB->AddressFile.Object);
- }
-
ExFreePool(FCB);
AFD_DbgPrint(MIN_TRACE,("Deleted (%x)\n", FCB));
-
- AFD_DbgPrint(MIN_TRACE,("Leaving\n"));
}
static NTSTATUS NTAPI
@@ -244,12 +257,6 @@
AFD_DbgPrint(MID_TRACE,("FCB %x\n", FCB));
- FCB->PollState |= AFD_EVENT_CLOSE;
- PollReeval( FCB->DeviceExt, FileObject );
- KillSelectsForFCB( FCB->DeviceExt, FileObject, FALSE );
-
- if( FCB->EventSelect ) ObDereferenceObject( FCB->EventSelect );
-
FileObject->FsContext = NULL;
SocketStateUnlock( FCB );
@@ -260,6 +267,28 @@
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
AFD_DbgPrint(MID_TRACE, ("Returning success.\n"));
+
+ return STATUS_SUCCESS;
+}
+
+static NTSTATUS NTAPI
+AfdCleanupSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
+ PIO_STACK_LOCATION IrpSp)
+{
+ PFILE_OBJECT FileObject = IrpSp->FileObject;
+ PAFD_FCB FCB = FileObject->FsContext;
+
+ if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
+
+ CleanupSocket( FCB );
+
+ KillSelectsForFCB( FCB->DeviceExt, FileObject, FALSE );
+
+ SocketStateUnlock( FCB );
+
+ Irp->IoStatus.Status = STATUS_SUCCESS;
+ Irp->IoStatus.Information = 0;
+ IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
return STATUS_SUCCESS;
}
@@ -344,6 +373,9 @@
/* Ditto the borrowing */
return AfdCloseSocket(DeviceObject, Irp, IrpSp);
+ case IRP_MJ_CLEANUP:
+ return AfdCleanupSocket(DeviceObject, Irp, IrpSp);
+
/* write data */
case IRP_MJ_WRITE:
return AfdConnectedSocketWriteData( DeviceObject, Irp, IrpSp, TRUE );
@@ -519,6 +551,7 @@
/* register driver routines */
DriverObject->MajorFunction[IRP_MJ_CLOSE] = AfdDispatch;
DriverObject->MajorFunction[IRP_MJ_CREATE] = AfdDispatch;
+ DriverObject->MajorFunction[IRP_MJ_CLEANUP] = AfdDispatch;
DriverObject->MajorFunction[IRP_MJ_WRITE] = AfdDispatch;
DriverObject->MajorFunction[IRP_MJ_READ] = AfdDispatch;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = AfdDispatch;