[ros-diffs] [cgutman] 53189: [LWIP] - Rewrite receive code to make it much simpler, handle some corner cases that weren't treated correctly, and fix the data corruption bug - Downloaded successfully (no data c...

cgutman at svn.reactos.org cgutman at svn.reactos.org
Thu Aug 11 21:52:41 UTC 2011


Author: cgutman
Date: Thu Aug 11 21:52:41 2011
New Revision: 53189

URL: http://svn.reactos.org/svn/reactos?rev=53189&view=rev
Log:
[LWIP]
- Rewrite receive code to make it much simpler, handle some corner cases that weren't treated correctly, and fix the data corruption bug
- Downloaded successfully (no data corruption): OpenOffice 2.4, OpenOffice 3.3, BitTorrent 7.2.1, Firefox 5, Firefox 3.6, Firefox 3, Firefox 2, Abyss Web Server, Opera 9.64, and Opera 11.01

Modified:
    trunk/reactos/lib/drivers/ip/transport/tcp/event.c
    trunk/reactos/lib/drivers/lwip/src/include/rosip.h
    trunk/reactos/lib/drivers/lwip/src/rostcp.c

Modified: trunk/reactos/lib/drivers/ip/transport/tcp/event.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/tcp/event.c?rev=53189&r1=53188&r2=53189&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/ip/transport/tcp/event.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/transport/tcp/event.c [iso-8859-1] Thu Aug 11 21:52:41 2011
@@ -451,59 +451,46 @@
     DereferenceObject(Connection);
 }
 
-u32_t
-TCPRecvEventHandler(void *arg, struct pbuf *p)
+VOID
+TCPRecvEventHandler(void *arg)
 {
     PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)arg;
     PTDI_BUCKET Bucket;
     PLIST_ENTRY Entry;
     PIRP Irp;
     PMDL Mdl;
-    UINT Received = 0;
+    UINT Received;
     UINT RecvLen;
     PUCHAR RecvBuffer;
-    
-    ASSERT(p);
-    
-    ReferenceObject(Connection);
-        
-    if ((Entry = ExInterlockedRemoveHeadList(&Connection->ReceiveRequest, &Connection->Lock)))
+    NTSTATUS Status;
+
+    ReferenceObject(Connection);
+
+    while ((Entry = ExInterlockedRemoveHeadList(&Connection->ReceiveRequest, &Connection->Lock)))
     {
         Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
         
         Irp = Bucket->Request.RequestContext;
         Mdl = Irp->MdlAddress;
-        
-        TI_DbgPrint(DEBUG_TCP,
-                    ("[IP, TCPRecvEventHandler] Getting the user buffer from %x\n", Mdl));
-        
+
         NdisQueryBuffer( Mdl, &RecvBuffer, &RecvLen );
-        
-        TI_DbgPrint(DEBUG_TCP,
-                    ("[IP, TCPRecvEventHandler] Reading %d bytes to %x\n", RecvLen, RecvBuffer));
-        
-        TI_DbgPrint(DEBUG_TCP, ("Connection: %x\n", Connection));
-        TI_DbgPrint(DEBUG_TCP, ("[IP, TCPRecvEventHandler] Connection->SocketContext: %x\n", Connection->SocketContext));
-        TI_DbgPrint(DEBUG_TCP, ("[IP, TCPRecvEventHandler] RecvBuffer: %x\n", RecvBuffer));
-        
-        RecvLen = MIN(p->tot_len, RecvLen);
-        
-        for (Received = 0; Received < RecvLen; Received += p->len, p = p->next)
-        {
-            RtlCopyMemory(RecvBuffer + Received, p->payload, p->len);
-        }
-        
-        TI_DbgPrint(DEBUG_TCP,("TCP Bytes: %d\n", Received));
-        
-        Bucket->Status = STATUS_SUCCESS;
+
+        Status = LibTCPGetDataFromConnectionQueue(Connection, RecvBuffer, RecvLen, &Received);
+        if (Status == STATUS_PENDING)
+        {
+            ExInterlockedInsertHeadList(&Connection->ReceiveRequest,
+                                        &Bucket->Entry,
+                                        &Connection->Lock);
+            break;
+        }
+
+        Bucket->Status = Status;
         Bucket->Information = Received;
-        
+
         CompleteBucket(Connection, Bucket, FALSE);
     }
 
     DereferenceObject(Connection);
-    
-    return Received;
 }
 
 VOID

Modified: trunk/reactos/lib/drivers/lwip/src/include/rosip.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/lwip/src/include/rosip.h?rev=53189&r1=53188&r2=53189&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/lwip/src/include/rosip.h [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/lwip/src/include/rosip.h [iso-8859-1] Thu Aug 11 21:52:41 2011
@@ -91,7 +91,7 @@
 extern void TCPAcceptEventHandler(void *arg, PTCP_PCB newpcb);
 extern void TCPSendEventHandler(void *arg, const u16_t space);
 extern void TCPFinEventHandler(void *arg, const err_t err);
-extern u32_t TCPRecvEventHandler(void *arg, struct pbuf *p);
+extern void TCPRecvEventHandler(void *arg);
 
 /* TCP functions */
 PTCP_PCB    LibTCPSocket(void *arg);

Modified: trunk/reactos/lib/drivers/lwip/src/rostcp.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/lwip/src/rostcp.c?rev=53189&r1=53188&r2=53189&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/lwip/src/rostcp.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/lwip/src/rostcp.c [iso-8859-1] Thu Aug 11 21:52:41 2011
@@ -207,37 +207,13 @@
         return ERR_OK;
     }
 
-    ASSERT(!LibTCPDequeuePacket(Connection));
-
     if (p)
     {
-        len = TCPRecvEventHandler(arg, p);
-        if (len == p->tot_len)
-        {
-            tcp_recved(pcb, len);
-
-            pbuf_free(p);
-
-            return ERR_OK;
-        }
-        else if (len != 0)
-        {
-            DbgPrint("UNTESTED CASE: NOT ALL DATA TAKEN! EXTRA DATA MAY BE LOST!\n");
-
-            tcp_recved(pcb, len);
-
-            /* Possible memory leak of pbuf here? */
-
-            return ERR_OK;
-        }
-        else
-        {
-            LibTCPEnqueuePacket(Connection, p);
-
-            tcp_recved(pcb, p->tot_len);
-
-            return ERR_OK;
-        }
+        LibTCPEnqueuePacket(Connection, p);
+
+        tcp_recved(pcb, p->tot_len);
+
+        TCPRecvEventHandler(arg);
     }
     else if (err == ERR_OK)
     {




More information about the Ros-diffs mailing list