[AFD] Introduce and use pool tags. Thanks go to Arty for assisting me with this....
[reactos.git] / drivers / network / afd / afd / write.c
index b91593c..6056761 100644 (file)
@@ -30,7 +30,7 @@ static NTSTATUS NTAPI SendComplete
 
     /*
      * The Irp parameter passed in is the IRP of the stream between AFD and
-     * TDI driver. It's not very usefull to us. We need the IRPs of the stream
+     * TDI driver. It's not very useful to us. We need the IRPs of the stream
      * between usermode and AFD. Those are chained from
      * FCB->PendingIrpList[FUNCTION_SEND] and you'll see them in the code
      * below as "NextIrp" ('cause they are the next usermode IRP to be
@@ -379,16 +379,26 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
             Status = QueueUserModeIrp(FCB, Irp, FUNCTION_SEND);
             if (Status == STATUS_PENDING)
             {
-                TdiSendDatagram(&FCB->SendIrp.InFlightRequest,
-                                FCB->AddressFile.Object,
-                                SendReq->BufferArray[0].buf,
-                                SendReq->BufferArray[0].len,
-                                TargetAddress,
-                                PacketSocketSendComplete,
-                                FCB);
+                Status = TdiSendDatagram(&FCB->SendIrp.InFlightRequest,
+                                         FCB->AddressFile.Object,
+                                         SendReq->BufferArray[0].buf,
+                                         SendReq->BufferArray[0].len,
+                                         TargetAddress,
+                                         PacketSocketSendComplete,
+                                         FCB);
+                if (Status != STATUS_PENDING)
+                {
+                    NT_VERIFY(RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]) == &Irp->Tail.Overlay.ListEntry);
+                    Irp->IoStatus.Status = Status;
+                    Irp->IoStatus.Information = 0;
+                    (void)IoSetCancelRoutine(Irp, NULL);
+                    UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, FALSE);
+                    UnlockRequest(Irp, IoGetCurrentIrpStackLocation(Irp));
+                    IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
+                }
             }
 
-            ExFreePool( TargetAddress );
+            ExFreePoolWithTag(TargetAddress, TAG_AFD_TDI_CONNECTION_INFORMATION);
 
             SocketStateUnlock(FCB);
 
@@ -442,15 +452,9 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
     AFD_DbgPrint(MID_TRACE,("Socket state %u\n", FCB->State));
 
     if( FCB->State != SOCKET_STATE_CONNECTED ) {
-        if (!(SendReq->AfdFlags & AFD_OVERLAPPED) && 
-            ((SendReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking))) {
-            AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
-            UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount, FALSE );
-            return UnlockAndMaybeComplete( FCB, STATUS_CANT_WAIT, Irp, 0 );
-        } else {
-            AFD_DbgPrint(MID_TRACE,("Queuing request\n"));
-            return LeaveIrpUntilLater( FCB, Irp, FUNCTION_SEND );
-        }
+        AFD_DbgPrint(MID_TRACE,("Socket not connected\n"));
+        UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount, FALSE );
+        return UnlockAndMaybeComplete( FCB, STATUS_INVALID_CONNECTION, Irp, 0 );
     }
 
     AFD_DbgPrint(MID_TRACE,("FCB->Send.BytesUsed = %u\n",
@@ -593,7 +597,11 @@ AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
 
     if (FCB->State == SOCKET_STATE_CREATED)
     {
-        if( FCB->LocalAddress ) ExFreePool( FCB->LocalAddress );
+        if (FCB->LocalAddress)
+        {
+            ExFreePoolWithTag(FCB->LocalAddress, TAG_AFD_TRANSPORT_ADDRESS);
+        }
+
         FCB->LocalAddress =
         TaBuildNullTransportAddress( ((PTRANSPORT_ADDRESS)SendReq->TdiConnection.RemoteAddress)->
                                       Address[0].AddressType );
@@ -637,16 +645,26 @@ AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
         Status = QueueUserModeIrp(FCB, Irp, FUNCTION_SEND);
         if (Status == STATUS_PENDING)
         {
-            TdiSendDatagram(&FCB->SendIrp.InFlightRequest,
-                            FCB->AddressFile.Object,
-                            SendReq->BufferArray[0].buf,
-                            SendReq->BufferArray[0].len,
-                            TargetAddress,
-                            PacketSocketSendComplete,
-                            FCB);
+            Status = TdiSendDatagram(&FCB->SendIrp.InFlightRequest,
+                                     FCB->AddressFile.Object,
+                                     SendReq->BufferArray[0].buf,
+                                     SendReq->BufferArray[0].len,
+                                     TargetAddress,
+                                     PacketSocketSendComplete,
+                                     FCB);
+            if (Status != STATUS_PENDING)
+            {
+                NT_VERIFY(RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]) == &Irp->Tail.Overlay.ListEntry);
+                Irp->IoStatus.Status = Status;
+                Irp->IoStatus.Information = 0;
+                (void)IoSetCancelRoutine(Irp, NULL);
+                UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, FALSE);
+                UnlockRequest(Irp, IoGetCurrentIrpStackLocation(Irp));
+                IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
+            }
         }
 
-        ExFreePool(TargetAddress);
+        ExFreePoolWithTag(TargetAddress, TAG_AFD_TDI_CONNECTION_INFORMATION);
 
         SocketStateUnlock(FCB);