Author: cmihail Date: Sun Jul 3 19:40:40 2011 New Revision: 52520
URL: http://svn.reactos.org/svn/reactos?rev=52520&view=rev Log: [AFD] merge r52502, r52510
[TCPIP] merge r52501, r52511
Modified: branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/info.c branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/main.c branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/read.c branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/write.c branches/GSoC_2011/TcpIpDriver/drivers/network/afd/include/afd.h branches/GSoC_2011/TcpIpDriver/drivers/network/tcpip/tcpip/fileobjs.c
Modified: branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/info.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/drivers/ne... ============================================================================== --- branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/info.c [iso-8859-1] (original) +++ branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/info.c [iso-8859-1] Sun Jul 3 19:40:40 2011 @@ -73,6 +73,19 @@ InfoReq->Information.Ulong++; CurrentEntry = CurrentEntry->Flink; } + + /* This needs to count too because when this is dispatched + * the user-mode IRP has already been completed and therefore + * will NOT be in our pending IRP list. We count this as one send + * outstanding although it could be multiple since we batch sends + * when waiting for the in flight request to return, so this number + * may not be accurate but it really doesn't matter that much since + * it's more or less a zero/non-zero comparison to determine whether + * we can shutdown the socket + */ + if (FCB->SendIrp.InFlightRequest) + InfoReq->Information.Ulong++; + break;
default:
Modified: branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/main.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/drivers/ne... ============================================================================== --- branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/main.c [iso-8859-1] (original) +++ branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/main.c [iso-8859-1] Sun Jul 3 19:40:40 2011 @@ -616,7 +616,8 @@ FCB->DisconnectIrp.InFlightRequest = NULL;
ASSERT(FCB->DisconnectPending); - //ASSERT(IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) || (FCB->DisconnectFlags & TDI_DISCONNECT_ABORT)); + ASSERT((IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest) || + (FCB->DisconnectFlags & TDI_DISCONNECT_ABORT));
if (NT_SUCCESS(Irp->IoStatus.Status) && (FCB->DisconnectFlags & TDI_DISCONNECT_RELEASE)) { @@ -666,11 +667,11 @@ NTSTATUS DoDisconnect(PAFD_FCB FCB) { - PAFD_DISCONNECT_INFO DisReq; - IO_STATUS_BLOCK Iosb; NTSTATUS Status;
ASSERT(FCB->DisconnectPending); + ASSERT((IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest) || + (FCB->DisconnectFlags & TDI_DISCONNECT_ABORT));
if (FCB->DisconnectIrp.InFlightRequest) { @@ -684,13 +685,14 @@
Status = TdiDisconnect(&FCB->DisconnectIrp.InFlightRequest, FCB->Connection.Object, - &DisReq->Timeout, + &FCB->DisconnectTimeout, FCB->DisconnectFlags, - &Iosb, + &FCB->DisconnectIrp.Iosb, DisconnectComplete, FCB, FCB->ConnectCallInfo, FCB->ConnectReturnInfo); + if (Status != STATUS_PENDING) { FCB->DisconnectPending = FALSE; @@ -704,7 +706,7 @@ { ASSERT(FCB->RemoteAddress);
- if (IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && FCB->DisconnectPending) + if (IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest && FCB->DisconnectPending) { /* Sends are done; fire off a TDI_DISCONNECT request */ DoDisconnect(FCB); @@ -769,9 +771,10 @@ Status = QueueUserModeIrp(FCB, Irp, FUNCTION_DISCONNECT); if (Status == STATUS_PENDING) { - if (IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) || (FCB->DisconnectFlags & TDI_DISCONNECT_ABORT)) + if ((IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest) || + (FCB->DisconnectFlags & TDI_DISCONNECT_ABORT)) { - /* Go ahead an execute the disconnect because we're ready for it */ + /* Go ahead and execute the disconnect because we're ready for it */ Status = DoDisconnect(FCB); }
Modified: branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/read.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/drivers/ne... ============================================================================== --- branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/read.c [iso-8859-1] (original) +++ branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/read.c [iso-8859-1] Sun Jul 3 19:40:40 2011 @@ -30,8 +30,8 @@ { if ((Status == STATUS_SUCCESS && !Information) || (!NT_SUCCESS(Status))) { - /* The socket has been closed */ - FCB->PollState |= AFD_EVENT_CLOSE; + /* The socket has been closed by the remote side */ + FCB->PollState |= AFD_EVENT_ABORT; FCB->PollStatus[FD_CLOSE_BIT] = Status; PollReeval( FCB->DeviceExt, FCB->FileObject );
Modified: branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/write.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/drivers/ne... ============================================================================== --- branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/write.c [iso-8859-1] (original) +++ branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/write.c [iso-8859-1] Sun Jul 3 19:40:40 2011 @@ -190,7 +190,10 @@ &FCB->SendIrp.Iosb, SendComplete, FCB ); - + } + else + { + /* Nothing is waiting so try to complete a pending disconnect */ RetryDisconnectCompletion(FCB); }
@@ -326,9 +329,28 @@ return UnlockAndMaybeComplete( FCB, Status, Irp, Information ); }
- if( !(SendReq = LockRequest(Irp, IrpSp))) - return UnlockAndMaybeComplete - ( FCB, STATUS_NO_MEMORY, Irp, TotalBytesCopied ); + if (FCB->DisconnectPending && (FCB->DisconnectFlags & TDI_DISCONNECT_RELEASE)) + { + /* We're pending a send shutdown so don't accept anymore sends */ + return UnlockAndMaybeComplete(FCB, STATUS_FILE_CLOSED, Irp, 0); + } + + if (FCB->PollState & (AFD_EVENT_CLOSE | AFD_EVENT_DISCONNECT)) + { + if (FCB->PollStatus[FD_CLOSE_BIT] == STATUS_SUCCESS) + { + /* This is a local send shutdown or a graceful remote disconnect */ + return UnlockAndMaybeComplete(FCB, STATUS_FILE_CLOSED, Irp, 0); + } + else + { + /* This is an unexpected remote disconnect */ + return UnlockAndMaybeComplete(FCB, FCB->PollStatus[FD_CLOSE_BIT], Irp, 0); + } + } + + if (!(SendReq = LockRequest(Irp, IrpSp))) + return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, TotalBytesCopied);
SendReq->BufferArray = LockBuffers( SendReq->BufferArray, SendReq->BufferCount,
Modified: branches/GSoC_2011/TcpIpDriver/drivers/network/afd/include/afd.h URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/drivers/ne... ============================================================================== --- branches/GSoC_2011/TcpIpDriver/drivers/network/afd/include/afd.h [iso-8859-1] (original) +++ branches/GSoC_2011/TcpIpDriver/drivers/network/afd/include/afd.h [iso-8859-1] Sun Jul 3 19:40:40 2011 @@ -184,6 +184,7 @@ UINT ConnSeq; USHORT DisconnectFlags; BOOLEAN DisconnectPending; + LARGE_INTEGER DisconnectTimeout; PTRANSPORT_ADDRESS LocalAddress, RemoteAddress; PTDI_CONNECTION_INFORMATION AddressFrom, ConnectCallInfo, ConnectReturnInfo; AFD_TDI_OBJECT AddressFile, Connection;
Modified: branches/GSoC_2011/TcpIpDriver/drivers/network/tcpip/tcpip/fileobjs.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/drivers/ne... ============================================================================== --- branches/GSoC_2011/TcpIpDriver/drivers/network/tcpip/tcpip/fileobjs.c [iso-8859-1] (original) +++ branches/GSoC_2011/TcpIpDriver/drivers/network/tcpip/tcpip/fileobjs.c [iso-8859-1] Sun Jul 3 19:40:40 2011 @@ -307,9 +307,21 @@ /* Sanity check */ ASSERT(Address->Address[0].Address[0].sin_port == AddrFile->Port); } + else if (!AddrIsUnspecified(&AddrFile->Address)) + { + / The client is trying to bind to a local address so allocate a port now too + AddrFile->Port = TCPAllocatePort(0); + + // Check for bind success + if (AddrFile->Port == 0xffff) + { + ExFreePoolWithTag(AddrFile, ADDR_FILE_TAG); + return STATUS_ADDRESS_ALREADY_EXISTS; + } + } else { - /* The client wants an unspecified port so we wait to see what the TCP library gives us */ + /* The client wants an unspecified port with an unspecified address so we wait to see what the TCP library gives us */ AddrFile->Port = 0; }