From ad39f83097b6c4a6d8c52671132c1bd3fac33df0 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Wed, 2 Jul 2025 11:37:10 +0200 Subject: [PATCH] Disconnect HttpServerConnection when AsioTlsStream is shut down --- lib/remote/httpserverconnection.cpp | 19 +++++++++++++++++++ lib/remote/httpserverconnection.hpp | 1 + 2 files changed, 20 insertions(+) diff --git a/lib/remote/httpserverconnection.cpp b/lib/remote/httpserverconnection.cpp index f6ec6ce87..bca378aa7 100644 --- a/lib/remote/httpserverconnection.cpp +++ b/lib/remote/httpserverconnection.cpp @@ -66,6 +66,7 @@ void HttpServerConnection::Start() IoEngine::SpawnCoroutine(m_IoStrand, [this, keepAlive](asio::yield_context yc) { ProcessMessages(yc); }); IoEngine::SpawnCoroutine(m_IoStrand, [this, keepAlive](asio::yield_context yc) { CheckLiveness(yc); }); + IoEngine::SpawnCoroutine(m_IoStrand, [this, keepAlive](asio::yield_context yc) { CheckStream(yc); }); } /** @@ -539,3 +540,21 @@ void HttpServerConnection::CheckLiveness(boost::asio::yield_context yc) } } } + +/** + * Checks if the @c AsioTlsStream has been closed to shut down the connection. + * + * @param yc The yield context for the coroutine of this function + */ +void HttpServerConnection::CheckStream(boost::asio::yield_context yc) +{ + using wait_type = boost::asio::socket_base::wait_type; + + while(!m_ShuttingDown){ + boost::system::error_code ec; + m_Stream->async_fill(yc[ec]); + if (ec) { + Disconnect(yc); + } + } +} diff --git a/lib/remote/httpserverconnection.hpp b/lib/remote/httpserverconnection.hpp index e4f7d257e..7bbae1d35 100644 --- a/lib/remote/httpserverconnection.hpp +++ b/lib/remote/httpserverconnection.hpp @@ -51,6 +51,7 @@ private: void ProcessMessages(boost::asio::yield_context yc); void CheckLiveness(boost::asio::yield_context yc); + void CheckStream(boost::asio::yield_context yc); }; }