[ros-diffs] [cgutman] 53173: [LWIP] - Fix user-initiated hard connection closures

cgutman at svn.reactos.org cgutman at svn.reactos.org
Thu Aug 11 06:39:19 UTC 2011


Author: cgutman
Date: Thu Aug 11 06:39:17 2011
New Revision: 53173

URL: http://svn.reactos.org/svn/reactos?rev=53173&view=rev
Log:
[LWIP]
- Fix user-initiated hard connection closures

Modified:
    trunk/reactos/lib/drivers/lwip/src/rostcp.c

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=53173&r1=53172&r2=53173&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 06:39:17 2011
@@ -643,7 +643,6 @@
 {
     struct lwip_callback_msg *msg = arg;
     PTCP_PCB pcb = msg->Input.Close.Connection->SocketContext;
-    int state;
 
     /* Empty the queue even if we're already "closed" */
     LibTCPEmptyQueue(msg->Input.Close.Connection);
@@ -657,29 +656,36 @@
     /* Clear the PCB pointer */
     msg->Input.Close.Connection->SocketContext = NULL;
 
-    /* Save the old PCB state */
-    state = pcb->state;
-
-    msg->Output.Close.Error = tcp_close(pcb);
-    if (!msg->Output.Close.Error)
-    {
-        if (msg->Input.Close.Callback)
-        {
-            /* Call the FIN handler in the cases where it will not be called by lwIP */
-            switch (state)
-            {
-                case CLOSED:
-                case LISTEN:
-                case SYN_SENT:
-                   TCPFinEventHandler(msg->Input.Close.Connection, ERR_OK);
-                   break;
-
-                default:
-                   break;
-            }
-        }
-    }
-    else
+    switch (pcb->state)
+    {
+        case CLOSED:
+        case LISTEN:
+        case SYN_SENT:
+           msg->Output.Close.Error = tcp_close(pcb);
+
+           if (!msg->Output.Close.Error && msg->Input.Close.Callback)
+               TCPFinEventHandler(msg->Input.Close.Connection, ERR_OK);
+           break;
+
+        default:
+           if (msg->Input.Close.Connection->SendShutdown &&
+               msg->Input.Close.Connection->ReceiveShutdown)
+           {
+               /* Abort the connection */
+               tcp_abort(pcb);
+
+               /* Aborts always succeed */
+               msg->Output.Close.Error = ERR_OK;
+           }
+           else
+           {
+               /* Start the graceful close process (or send RST for pending data) */
+               msg->Output.Close.Error = tcp_close(pcb);
+           }
+           break;
+    }
+
+    if (msg->Output.Close.Error)
     {
         /* Restore the PCB pointer */
         msg->Input.Close.Connection->SocketContext = pcb;




More information about the Ros-diffs mailing list