- Handle TDI receive completion better

svn path=/trunk/; revision=53028
This commit is contained in:
Cameron Gutman 2011-08-02 13:46:16 +00:00
parent 6b39d13104
commit 02b56ebcbc

View file

@ -23,22 +23,38 @@
*/
#include "afd.h"
static VOID HandleEOFOnIrp( PAFD_FCB FCB, NTSTATUS Status, ULONG_PTR Information )
static VOID HandleReceiveComplete( PAFD_FCB FCB, NTSTATUS Status, ULONG_PTR Information )
{
if (Status != STATUS_SUCCESS)
{
FCB->TdiReceiveClosed = TRUE;
FCB->Recv.BytesUsed = 0;
/* Receive successful with new data */
if (Status == STATUS_SUCCESS && Information)
{
FCB->Recv.Content = Information;
}
/* Receive successful with no data (graceful closure) */
else if (Status == STATUS_SUCCESS)
{
FCB->Recv.Content = 0;
FCB->TdiReceiveClosed = TRUE;
/* Signal graceful receive shutdown */
FCB->PollState |= AFD_EVENT_DISCONNECT;
FCB->PollStatus[FD_CLOSE_BIT] = Status;
PollReeval( FCB->DeviceExt, FCB->FileObject );
}
/* Receive failed with no data (unexpected closure) */
else
{
FCB->Recv.Content = 0;
FCB->TdiReceiveClosed = TRUE;
/* Signal complete connection failure immediately */
FCB->PollState |= AFD_EVENT_CLOSE;
FCB->PollStatus[FD_CLOSE_BIT] = Status;
PollReeval( FCB->DeviceExt, FCB->FileObject );
}
else if (Status == STATUS_SUCCESS && !Information)
{
/* Wait to signal graceful close until all data is read */
FCB->TdiReceiveClosed = TRUE;
}
}
@ -228,17 +244,6 @@ static NTSTATUS ReceiveActivity( PAFD_FCB FCB, PIRP Irp ) {
FCB->PollStatus[FD_READ_BIT] = STATUS_SUCCESS;
PollReeval( FCB->DeviceExt, FCB->FileObject );
}
else if (CantReadMore(FCB) &&
!(FCB->PollState & (AFD_EVENT_CLOSE | AFD_EVENT_ABORT)))
{
FCB->PollState &= ~AFD_EVENT_RECEIVE;
/* Signal graceful receive shutdown */
FCB->PollState |= AFD_EVENT_DISCONNECT;
FCB->PollStatus[FD_CLOSE_BIT] = STATUS_SUCCESS;
PollReeval( FCB->DeviceExt, FCB->FileObject );
}
else
{
FCB->PollState &= ~AFD_EVENT_RECEIVE;
@ -273,9 +278,6 @@ NTSTATUS NTAPI ReceiveComplete
ASSERT(FCB->ReceiveIrp.InFlightRequest == Irp);
FCB->ReceiveIrp.InFlightRequest = NULL;
FCB->Recv.Content = Irp->IoStatus.Information;
FCB->Recv.BytesUsed = 0;
if( FCB->State == SOCKET_STATE_CLOSED ) {
/* Cleanup our IRP queue because the FCB is being destroyed */
while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_RECV] ) ) {
@ -298,7 +300,7 @@ NTSTATUS NTAPI ReceiveComplete
return STATUS_INVALID_PARAMETER;
}
HandleEOFOnIrp( FCB, Irp->IoStatus.Status, Irp->IoStatus.Information );
HandleReceiveComplete( FCB, Irp->IoStatus.Status, Irp->IoStatus.Information );
ReceiveActivity( FCB, NULL );