Allow cancelling of listen IRPs
Modified: trunk/reactos/drivers/lib/ip/transport/tcp/accept.c
Modified: trunk/reactos/drivers/net/afd/afd/listen.c
Modified: trunk/reactos/drivers/net/tcpip/tcpip/dispatch.c

Modified: trunk/reactos/drivers/lib/ip/transport/tcp/accept.c
--- trunk/reactos/drivers/lib/ip/transport/tcp/accept.c	2005-03-13 21:41:44 UTC (rev 14036)
+++ trunk/reactos/drivers/lib/ip/transport/tcp/accept.c	2005-03-13 21:47:04 UTC (rev 14037)
@@ -109,16 +109,16 @@
     
     TcpipRecursiveMutexEnter( &TCPLock, TRUE );
     
-    for( ListEntry = Listener->ListenRequest.Flink;
-	 ListEntry != &Listener->ListenRequest;
-	 ListEntry = ListEntry->Flink ) {
+    ListEntry = Listener->ListenRequest.Flink;
+    while ( ListEntry != &Listener->ListenRequest ) {
 	Bucket = CONTAINING_RECORD(ListEntry, TDI_BUCKET, Entry);
+	ListEntry = ListEntry->Flink;
 
-	if( Bucket->Request.Handle.ConnectionContext == Connection ) {
+	if( Bucket->AssociatedEndpoint == Connection ) {
 #ifdef MEMTRACK
 	    UntrackFL( __FILE__, __LINE__, Bucket->Request.RequestContext );
 #endif
-	    RemoveEntryList( ListEntry );
+	    RemoveEntryList( ListEntry->Blink );
 	    ExFreePool( Bucket );
 	}
     }

Modified: trunk/reactos/drivers/net/afd/afd/listen.c
--- trunk/reactos/drivers/net/afd/afd/listen.c	2005-03-13 21:41:44 UTC (rev 14036)
+++ trunk/reactos/drivers/net/afd/afd/listen.c	2005-03-13 21:47:04 UTC (rev 14037)
@@ -80,6 +80,11 @@
     PAFD_FCB FCB = (PAFD_FCB)Context;
     PAFD_TDI_OBJECT_QELT Qelt;
 
+    if ( Irp->Cancel ) {
+	/* FIXME: is this anything else we need to do? */
+	return STATUS_SUCCESS;
+    }
+
     if( !SocketAcquireStateLock( FCB ) ) return Status;
 
     FCB->ListenIrp.InFlightRequest = NULL;

Modified: trunk/reactos/drivers/net/tcpip/tcpip/dispatch.c
--- trunk/reactos/drivers/net/tcpip/tcpip/dispatch.c	2005-03-13 21:41:44 UTC (rev 14036)
+++ trunk/reactos/drivers/net/tcpip/tcpip/dispatch.c	2005-03-13 21:47:04 UTC (rev 14037)
@@ -219,6 +219,52 @@
 }
 
 
+VOID DDKAPI DispCancelListenRequest(
+    PDEVICE_OBJECT Device,
+    PIRP Irp)
+/*
+ * FUNCTION: Cancels a listen IRP
+ * ARGUMENTS:
+ *     Device = Pointer to device object
+ *     Irp    = Pointer to an I/O request packet
+ */
+{
+    PIO_STACK_LOCATION IrpSp;
+    PTRANSPORT_CONTEXT TranContext;
+    PFILE_OBJECT FileObject;
+    PCONNECTION_ENDPOINT Connection;
+    /*NTSTATUS Status = STATUS_SUCCESS;*/
+
+    TI_DbgPrint(DEBUG_IRP, ("Called.\n"));
+
+    IrpSp         = IoGetCurrentIrpStackLocation(Irp);
+    FileObject    = IrpSp->FileObject;
+    TranContext   = (PTRANSPORT_CONTEXT)FileObject->FsContext;
+    ASSERT( TDI_LISTEN == IrpSp->MinorFunction);
+
+    TI_DbgPrint(DEBUG_IRP, ("IRP at (0x%X).\n", Irp));
+
+#ifdef DBG
+    if (!Irp->Cancel)
+        TI_DbgPrint(MIN_TRACE, ("Irp->Cancel is FALSE, should be TRUE.\n"));
+#endif
+
+    /* Try canceling the request */
+    Connection = (PCONNECTION_ENDPOINT)TranContext->Handle.ConnectionContext;
+    TCPAbortListenForSocket(
+	    Connection->AddressFile->Listener,
+	    Connection );
+
+    IoReleaseCancelSpinLock(Irp->CancelIrql);
+
+    DispDataRequestComplete(Irp, STATUS_CANCELLED, 0);
+    
+    DispCancelComplete(FileObject);
+
+    TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
+}
+
+
 NTSTATUS DispTdiAccept(
   PIRP Irp)
 /*
@@ -536,6 +582,12 @@
 	  Status = TCPListen( Connection->AddressFile->Listener, 1024 ); 
 	  /* BACKLOG */
   }
+  if( NT_SUCCESS(Status) ) {
+      Status = DispPrepareIrpForCancel
+          (TranContext->Handle.ConnectionContext, 
+           Irp, 
+           (PDRIVER_CANCEL)DispCancelListenRequest);
+  }
 
   if( NT_SUCCESS(Status) ) {
       Status = TCPAccept