Author: cgutman Date: Mon Aug 8 21:57:06 2011 New Revision: 53144
URL: http://svn.reactos.org/svn/reactos?rev=53144&view=rev Log: [AFD] - Fix shutdown() for datagram sockets - Share some code between SD_BOTH and SD_RECEIVE
Modified: 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/main.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/afd/mai... ============================================================================== --- trunk/reactos/drivers/network/afd/afd/main.c [iso-8859-1] (original) +++ trunk/reactos/drivers/network/afd/afd/main.c [iso-8859-1] Mon Aug 8 21:57:06 2011 @@ -680,38 +680,52 @@ return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp, 0 );
- /* Shutdown(SD_SEND) */ + /* Send direction only */ if ((DisReq->DisconnectType & AFD_DISCONNECT_SEND) && !(DisReq->DisconnectType & AFD_DISCONNECT_RECV)) { /* Perform a controlled disconnect */ Flags = TDI_DISCONNECT_RELEASE; } - /* Shutdown(SD_RECEIVE) */ - else if ((DisReq->DisconnectType & AFD_DISCONNECT_RECV) && - !(DisReq->DisconnectType & AFD_DISCONNECT_SEND)) + /* Receive direction or both */ + else { /* Mark that we can't issue another receive request */ FCB->TdiReceiveClosed = TRUE;
- /* Discard any pending data */ - FCB->Recv.Content = 0; - FCB->Recv.BytesUsed = 0; - - /* Mark us as overread to complete future reads with an error */ - FCB->Overread = TRUE; + /* These are only for connection-oriented sockets */ + if (!(FCB->Flags & AFD_ENDPOINT_CONNECTIONLESS)) + { + /* Try to cancel a pending TDI receive IRP if there was one in progress */ + if (FCB->ReceiveIrp.InFlightRequest) + IoCancelIrp(FCB->ReceiveIrp.InFlightRequest); + + /* Discard any pending data */ + FCB->Recv.Content = 0; + FCB->Recv.BytesUsed = 0; + + /* Mark us as overread to complete future reads with an error */ + FCB->Overread = TRUE; + + /* Set a successful close status to indicate a shutdown on overread */ + FCB->PollStatus[FD_CLOSE_BIT] = STATUS_SUCCESS; + }
/* Clear the receive event */ FCB->PollState &= ~AFD_EVENT_RECEIVE;
- /* We're done (no need to tell the TDI transport driver) */ - return UnlockAndMaybeComplete( FCB, STATUS_SUCCESS, Irp, 0 ); - } - /* Shutdown(SD_BOTH) */ - else - { - /* Perform an abortive disconnect */ - Flags = TDI_DISCONNECT_ABORT; + /* Receive direction only */ + if ((DisReq->DisconnectType & AFD_DISCONNECT_RECV) && + !(DisReq->DisconnectType & AFD_DISCONNECT_SEND)) + { + /* No need to tell the transport driver for receive direction only */ + return UnlockAndMaybeComplete( FCB, STATUS_SUCCESS, Irp, 0 ); + } + else + { + /* Perform an abortive disconnect */ + Flags = TDI_DISCONNECT_ABORT; + } }
if (!(FCB->Flags & AFD_ENDPOINT_CONNECTIONLESS)) @@ -785,9 +799,10 @@ ExFreePool(FCB->RemoteAddress);
FCB->RemoteAddress = NULL; + }
- FCB->PollState &= ~AFD_EVENT_SEND; - } + FCB->PollState &= ~AFD_EVENT_SEND; + FCB->SendClosed = TRUE; }
return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
Modified: trunk/reactos/drivers/network/afd/afd/read.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/afd/rea... ============================================================================== --- trunk/reactos/drivers/network/afd/afd/read.c [iso-8859-1] (original) +++ trunk/reactos/drivers/network/afd/afd/read.c [iso-8859-1] Mon Aug 8 21:57:06 2011 @@ -27,8 +27,13 @@ { FCB->Recv.BytesUsed = 0;
+ /* We got closed while the receive was in progress */ + if (FCB->TdiReceiveClosed) + { + FCB->Recv.Content = 0; + } /* Receive successful with new data */ - if (Status == STATUS_SUCCESS && Information) + else if (Status == STATUS_SUCCESS && Information) { FCB->Recv.Content = Information; } @@ -693,6 +698,13 @@ return UnlockAndMaybeComplete ( FCB, STATUS_INVALID_PARAMETER, Irp, 0 ); } + + if (FCB->TdiReceiveClosed) + { + AFD_DbgPrint(MIN_TRACE,("Receive closed\n")); + return UnlockAndMaybeComplete(FCB, STATUS_FILE_CLOSED, Irp, 0); + } + if( !(RecvReq = LockRequest( Irp, IrpSp )) ) return UnlockAndMaybeComplete ( FCB, STATUS_NO_MEMORY, Irp, 0 );
Modified: trunk/reactos/drivers/network/afd/afd/write.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/afd/wri... ============================================================================== --- trunk/reactos/drivers/network/afd/afd/write.c [iso-8859-1] (original) +++ trunk/reactos/drivers/network/afd/afd/write.c [iso-8859-1] Mon Aug 8 21:57:06 2011 @@ -516,6 +516,13 @@ return UnlockAndMaybeComplete ( FCB, STATUS_INVALID_PARAMETER, Irp, 0 ); } + + if (FCB->SendClosed) + { + AFD_DbgPrint(MIN_TRACE,("No more sends\n")); + return UnlockAndMaybeComplete(FCB, STATUS_FILE_CLOSED, Irp, 0); + } + if( !(SendReq = LockRequest( Irp, IrpSp )) ) return UnlockAndMaybeComplete ( FCB, STATUS_NO_MEMORY, Irp, 0 );