From 71f76561bcab7dc4d379ddb5819a600e7b644a8a Mon Sep 17 00:00:00 2001
From: Christian Huitema <huitema@huitema.net>
Date: Thu, 30 Nov 2017 10:41:09 -0800
Subject: [PATCH] Fixed bug in closing sequence. Now ensures that the peer
 sends a connection_close in response to a received closing message.

---
 CMakeSettings.json | 37 +++++++++++++++++++++++++++++++++++++
 picoquic/frames.c  |  4 ++--
 picoquic/sender.c  | 11 ++---------
 3 files changed, 41 insertions(+), 11 deletions(-)
 create mode 100644 CMakeSettings.json

diff --git a/CMakeSettings.json b/CMakeSettings.json
new file mode 100644
index 00000000..e8c1f1df
--- /dev/null
+++ b/CMakeSettings.json
@@ -0,0 +1,37 @@
+{
+    // See https://go.microsoft.com//fwlink//?linkid=834763 for more information about this file.
+    "configurations": [
+        {
+        "name": "x86-Debug",
+        "generator": "Visual Studio 15 2017",
+        "configurationType" : "Debug",
+        "buildRoot":  "${env.LOCALAPPDATA}\\CMakeBuild\\${workspaceHash}\\build\\${name}",
+        "cmakeCommandArgs":  "",
+        "buildCommandArgs": "-m -v:minimal"
+        },
+        {
+        "name": "x86-Release",
+        "generator": "Visual Studio 15 2017",
+        "configurationType" : "Release",
+        "buildRoot":  "${env.LOCALAPPDATA}\\CMakeBuild\\${workspaceHash}\\build\\${name}",
+        "cmakeCommandArgs":  "",
+        "buildCommandArgs": "-m -v:minimal"
+        },
+        {
+        "name": "x64-Debug",
+        "generator": "Visual Studio 15 2017 Win64",
+        "configurationType" : "Debug",
+        "buildRoot":  "${env.LOCALAPPDATA}\\CMakeBuild\\${workspaceHash}\\build\\${name}",
+        "cmakeCommandArgs":  "",
+        "buildCommandArgs": "-m -v:minimal"
+        },
+        {
+        "name": "x64-Release",
+        "generator": "Visual Studio 15 2017 Win64",
+        "configurationType" : "Release",
+        "buildRoot":  "${env.LOCALAPPDATA}\\CMakeBuild\\${workspaceHash}\\build\\${name}",
+        "cmakeCommandArgs":  "",
+        "buildCommandArgs": "-m -v:minimal"
+        }
+    ]
+}
\ No newline at end of file
diff --git a/picoquic/frames.c b/picoquic/frames.c
index 96c3a957..21432414 100644
--- a/picoquic/frames.c
+++ b/picoquic/frames.c
@@ -2463,7 +2463,7 @@ int picoquic_decode_connection_close_frame(picoquic_cnx_t * cnx, uint8_t * bytes
 
     if (ret == 0)
     {
-        cnx->cnx_state = picoquic_state_disconnected;
+        cnx->cnx_state = picoquic_state_closing_received;
         cnx->remote_error = error_code;
         *consumed = (size_t)(string_length + byte_index);
         if (cnx->callback_fn)
@@ -2610,7 +2610,7 @@ int picoquic_decode_application_close_frame(picoquic_cnx_t * cnx, uint8_t * byte
 
     if (ret == 0)
     {
-        cnx->cnx_state = picoquic_state_disconnected;
+        cnx->cnx_state = picoquic_state_closing_received;
         cnx->remote_application_error = error_code;
         *consumed = (size_t)(string_length + byte_index);
         if (cnx->callback_fn)
diff --git a/picoquic/sender.c b/picoquic/sender.c
index d5e4c4d6..b5f65cb2 100644
--- a/picoquic/sender.c
+++ b/picoquic/sender.c
@@ -774,16 +774,9 @@ int picoquic_prepare_packet(picoquic_cnx_t * cnx, picoquic_packet * packet,
         packet->send_time = current_time;
 
         /* Send the disconnect frame */
-        if (cnx->local_error == 0)
-        {
-            ret = picoquic_prepare_application_close_frame(cnx, bytes + length,
+        ret = picoquic_prepare_connection_close_frame(cnx, bytes + length,
                 cnx->send_mtu - checksum_overhead - length, &consumed);
-        }
-        else
-        {
-            ret = picoquic_prepare_connection_close_frame(cnx, bytes + length,
-                cnx->send_mtu - checksum_overhead - length, &consumed);
-        }
+
         if (ret == 0)
         {
             length += consumed;
-- 
GitLab