https://git.reactos.org/?p=reactos.git;a=commitdiff;h=666bac44c01cdee2d50dd7e01228b1e87a1afba5

commit 666bac44c01cdee2d50dd7e01228b1e87a1afba5
Author:     Sylvain Deverre <[email protected]>
AuthorDate: Sun Apr 26 18:40:47 2020 +0200
Commit:     GitHub <[email protected]>
CommitDate: Sun Apr 26 18:40:47 2020 +0200

    [LWIP] Use tcp_close when both shut_rx and shut_tx are set. Fixes 
CORE-16868 (#2582)
---
 sdk/lib/drivers/lwip/src/rostcp.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/sdk/lib/drivers/lwip/src/rostcp.c 
b/sdk/lib/drivers/lwip/src/rostcp.c
index 8e22ccd5c2d..de5564642b8 100644
--- a/sdk/lib/drivers/lwip/src/rostcp.c
+++ b/sdk/lib/drivers/lwip/src/rostcp.c
@@ -647,11 +647,24 @@ LibTCPShutdownCallback(void *arg)
      * PCB without telling us if we shutdown TX and RX. To avoid these 
problems, we'll clear the
      * socket context if we have called shutdown for TX and RX.
      */
-    if (msg->Input.Shutdown.shut_rx) {
-        msg->Output.Shutdown.Error = tcp_shutdown(pcb, TRUE, FALSE);
+    if (msg->Input.Shutdown.shut_rx != msg->Input.Shutdown.shut_tx) {
+        if (msg->Input.Shutdown.shut_rx) {
+            msg->Output.Shutdown.Error = tcp_shutdown(pcb, TRUE, FALSE);
+        }
+        if (msg->Input.Shutdown.shut_tx) {
+            msg->Output.Shutdown.Error = tcp_shutdown(pcb, FALSE, TRUE);
+        }
+    }
+    else if (msg->Input.Shutdown.shut_rx) {
+        /* We received both RX and TX requests, which seems to mean closing 
connection from TDI.
+         * So call tcp_close, otherwise we risk to be put in TCP_WAIT_* 
states, which makes further
+         * attempts to close the socket to fail in this state.
+         */
+        msg->Output.Shutdown.Error = tcp_close(pcb);
     }
-    if (msg->Input.Shutdown.shut_tx) {
-        msg->Output.Shutdown.Error = tcp_shutdown(pcb, FALSE, TRUE);
+    else {
+        /* This case shouldn't happen */
+        DbgPrint("Requested socket shutdown(0, 0) !\n");
     }
 
     if (!msg->Output.Shutdown.Error)

Reply via email to