From 18aad09dd4e2f87a741ccd70efacc86c958f9df5 Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Mon, 22 Jul 2024 13:08:09 +0200 Subject: [PATCH] Make sure that connection is closed if disconnected remotely --- src/mhd2/stream_process_states.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/mhd2/stream_process_states.c b/src/mhd2/stream_process_states.c index b0b8d5c2..5f82a360 100644 --- a/src/mhd2/stream_process_states.c +++ b/src/mhd2/stream_process_states.c @@ -210,6 +210,19 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) /* 'daemon' is not used if epoll is not available and asserts are disabled */ (void) d; /* Mute compiler warning */ + if ((c->sk_rmt_shut_wr) && (MHD_CONNECTION_START_REPLY > c->state)) + { + if (0 == c->read_buffer_offset) + { /* Read buffer is empty, connection state is actual */ + mhd_conn_pre_close (c, + (MHD_CONNECTION_INIT == c->state) ? + mhd_CONN_CLOSE_HTTP_COMPLETED : + mhd_CONN_CLOSE_CLIENT_SHUTDOWN_EARLY, + NULL); + return false; + } + } + mhd_assert (c->resuming || ! c->suspended); if (c->resuming) { @@ -466,6 +479,16 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) return true; } + if ((c->sk_rmt_shut_wr) && (MHD_CONNECTION_START_REPLY > c->state)) + { + mhd_conn_pre_close (c, + (MHD_CONNECTION_INIT == c->state) ? + mhd_CONN_CLOSE_HTTP_COMPLETED : + mhd_CONN_CLOSE_CLIENT_SHUTDOWN_EARLY, + NULL); + return false; + } + if (mhd_stream_check_timedout (c)) // TODO: centralise timeout checks { mhd_conn_pre_close_timedout (c);