From ddd3bd5f7a86b13b07cc7965b179d8b50299d997 Mon Sep 17 00:00:00 2001 From: Claudiu Mihail Date: Tue, 26 Jul 2011 11:25:24 +0000 Subject: [PATCH] [lwIP/TCPIP] - Fix completing IRPs with 0 bytes received when getting the data from the connection's packet queue - Eliminate memory leaks caused by unreleased pbufs - Get rid of some commented code In principle the speed issue with lwIP should be pretty much solved now. There's still some minor things to iron out that testing will reveal probably. Initial tests like running opera, downloading stuff etc seem to be very encouraging however. svn path=/branches/GSoC_2011/TcpIpDriver/; revision=52894 --- lib/drivers/ip/transport/tcp/event.c | 15 +-------------- lib/drivers/ip/transport/tcp/tcp.c | 13 +++++++++---- lib/drivers/lwip/src/rostcp.c | 6 +++--- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/lib/drivers/ip/transport/tcp/event.c b/lib/drivers/ip/transport/tcp/event.c index b9b88220e53..1729b13a2af 100644 --- a/lib/drivers/ip/transport/tcp/event.c +++ b/lib/drivers/ip/transport/tcp/event.c @@ -46,7 +46,6 @@ BucketCompletionWorker(PVOID Context) ExFreePoolWithTag(Bucket, TDI_BUCKET_TAG); } -static VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, BOOLEAN Synchronous) { @@ -149,23 +148,11 @@ TCPFinEventHandler(void *arg, err_t err) DbgPrint("[IP, TCPFinEventHandler] Called for Connection( 0x%x )-> SocketContext = pcb (0x%x)\n", Connection, Connection->SocketContext); /* Only clear the pointer if the shutdown was caused by an error */ - if ((err != ERR_OK))// && (status != STATUS_REMOTE_DISCONNECT)) + if ((err != ERR_OK)) { /* We're already closed by the error so we don't want to call lwip_close */ DbgPrint("[IP, TCPFinEventHandler] MAKING Connection( 0x%x )-> SocketContext = pcb (0x%x) NULL\n", Connection, Connection->SocketContext); - // close all possible callbacks - /*tcp_arg((PTCP_PCB)Connection->SocketContext, NULL); - - if (((PTCP_PCB)Connection->SocketContext)->state != LISTEN) - { - tcp_recv((PTCP_PCB)Connection->SocketContext, NULL); - tcp_sent((PTCP_PCB)Connection->SocketContext, NULL); - tcp_err((PTCP_PCB)Connection->SocketContext, NULL); - } - - tcp_accept((PTCP_PCB)Connection->SocketContext, NULL);*/ - Connection->SocketContext = NULL; } diff --git a/lib/drivers/ip/transport/tcp/tcp.c b/lib/drivers/ip/transport/tcp/tcp.c index f482ea1fdaa..5b25b5f9c56 100644 --- a/lib/drivers/ip/transport/tcp/tcp.c +++ b/lib/drivers/ip/transport/tcp/tcp.c @@ -428,7 +428,7 @@ NTSTATUS TCPReceiveData /* Freed in TCPSocketState */ Bucket = ExAllocatePoolWithTag( NonPagedPool, sizeof(*Bucket), TDI_BUCKET_TAG ); - if( !Bucket ) + if (!Bucket) { TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Failed to allocate bucket\n")); UnlockObject(Connection, OldIrql); @@ -438,20 +438,25 @@ NTSTATUS TCPReceiveData Bucket->Request.RequestNotifyObject = Complete; Bucket->Request.RequestContext = Context; - *BytesReceived = 0; - + InsertTailList( &Connection->ReceiveRequest, &Bucket->Entry ); TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Queued read irp\n")); UnlockObject(Connection, OldIrql); TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Leaving. Status = STATUS_PENDING\n")); + + (*BytesReceived) = 0; + } + else + { + (*BytesReceived) = Received; } DbgPrint("[IP, TCPReceiveData] Leaving. Status = %s\n", Status == STATUS_PENDING? "STATUS_PENDING" : "STATUS_SUCCESS"); - return STATUS_PENDING; + return Status; } NTSTATUS TCPSendData diff --git a/lib/drivers/lwip/src/rostcp.c b/lib/drivers/lwip/src/rostcp.c index 546b07ee601..987f38e722a 100755 --- a/lib/drivers/lwip/src/rostcp.c +++ b/lib/drivers/lwip/src/rostcp.c @@ -47,7 +47,7 @@ LibTCPEmptyQueue(PCONNECTION_ENDPOINT Connection) qp = CONTAINING_RECORD(Entry, QUEUE_ENTRY, ListEntry); // reenable this later - //pbuf_free(qp->p); + pbuf_free(qp->p); ExFreePoolWithTag(qp, LWIP_TAG); } @@ -92,7 +92,7 @@ NTSTATUS LibTCPGetDataFromConnectionQueue(PCONNECTION_ENDPOINT Connection, PUCHA RecvLen = MIN(p->tot_len, RecvLen); - for ((*Received) = 0; (*Received) < RecvLen; *Received += p->len, p = p->next) + for ((*Received) = 0; (*Received) < RecvLen; (*Received) += p->len, p = p->next) { DbgPrint("[lwIP, LibTCPGetDataFromConnectionQueue] 0x%x: Copying %d bytes to 0x%x from 0x%x\n", p, p->len, ((PUCHAR)RecvBuffer) + (*Received), p->payload); @@ -101,7 +101,7 @@ NTSTATUS LibTCPGetDataFromConnectionQueue(PCONNECTION_ENDPOINT Connection, PUCHA } // reenable this later - //pbuf_free(qp->p); + pbuf_free(qp->p); ExFreePoolWithTag(qp, LWIP_TAG); Status = STATUS_SUCCESS;