From c0ab87a39ac45ada27a5842c2cfd5bb7e362c7a6 Mon Sep 17 00:00:00 2001 From: Emmanuel Bachlitzanakis <115871174+EmBachlitzanakis@users.noreply.github.com> Date: Tue, 10 Jun 2025 11:15:41 +0300 Subject: [PATCH 1/4] Update app.h --- include/crow/app.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/include/crow/app.h b/include/crow/app.h index 9e89a1342..39d811194 100644 --- a/include/crow/app.h +++ b/include/crow/app.h @@ -563,13 +563,7 @@ namespace crow else #endif { - // TODO(EDev): Move these 6 lines to a method in http_server. - std::vector websockets_to_close = websockets_; - for (auto websocket : websockets_to_close) - { - CROW_LOG_INFO << "Quitting Websocket: " << websocket; - websocket->close("Server Application Terminated"); - } + server_->close_websockets(websockets_); if (server_) { server_->stop(); } } } From 52656e6829e6aed5d755aacb1803b0c509a520c2 Mon Sep 17 00:00:00 2001 From: Emmanuel Bachlitzanakis <115871174+EmBachlitzanakis@users.noreply.github.com> Date: Tue, 10 Jun 2025 11:16:37 +0300 Subject: [PATCH 2/4] Update http_server.h --- include/crow/http_server.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/crow/http_server.h b/include/crow/http_server.h index d364ba2d6..9a07dee9c 100644 --- a/include/crow/http_server.h +++ b/include/crow/http_server.h @@ -251,6 +251,18 @@ namespace crow // NOTE: Already documented in "crow/app.h" io_context_.stop(); // Close main io_service } + void close_websockets(const std::vector& websockets, + const std::string& reason = "Server Application Terminated") + { + // Make a copy to avoid issues if closing modifies the original collection + std::vector websockets_to_close = websockets; + for (auto websocket : websockets_to_close) + { + CROW_LOG_INFO << "Quitting Websocket: " << websocket; + websocket->close(reason); + } + } + uint16_t port() const { return acceptor_.local_endpoint().port(); } From 864200bb24aa0799ef88a26a9e11a5c3e069ccde Mon Sep 17 00:00:00 2001 From: Emmanuel Bachlitzanakis <115871174+EmBachlitzanakis@users.noreply.github.com> Date: Wed, 11 Jun 2025 17:34:50 +0300 Subject: [PATCH 3/4] Review Changes requested --- include/crow/app.h | 13 ++++++++++++- include/crow/http_server.h | 13 +------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/crow/app.h b/include/crow/app.h index 39d811194..7424da068 100644 --- a/include/crow/app.h +++ b/include/crow/app.h @@ -563,11 +563,22 @@ namespace crow else #endif { - server_->close_websockets(websockets_); + close_websockets(websockets_); if (server_) { server_->stop(); } } } + void close_websockets(const std::vector& websockets) + { + std::vector websockets_to_close = websockets; + for (auto websocket : websockets_to_close) + { + CROW_LOG_INFO << "Quitting Websocket: " << websocket; + websocket->close("Websocket Closed"); + } + } + + void add_websocket(crow::websocket::connection* conn) { websockets_.push_back(conn); diff --git a/include/crow/http_server.h b/include/crow/http_server.h index 9a07dee9c..5f336d5bc 100644 --- a/include/crow/http_server.h +++ b/include/crow/http_server.h @@ -251,18 +251,7 @@ namespace crow // NOTE: Already documented in "crow/app.h" io_context_.stop(); // Close main io_service } - void close_websockets(const std::vector& websockets, - const std::string& reason = "Server Application Terminated") - { - // Make a copy to avoid issues if closing modifies the original collection - std::vector websockets_to_close = websockets; - for (auto websocket : websockets_to_close) - { - CROW_LOG_INFO << "Quitting Websocket: " << websocket; - websocket->close(reason); - } - } - + uint16_t port() const { return acceptor_.local_endpoint().port(); } From 10a646f53d65791c5341cbac7c1d44e886c528c1 Mon Sep 17 00:00:00 2001 From: Emmanuel Bachlitzanakis <115871174+EmBachlitzanakis@users.noreply.github.com> Date: Fri, 13 Jun 2025 10:07:10 +0300 Subject: [PATCH 4/4] Requested Close_websockets() signature change --- include/crow/app.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/crow/app.h b/include/crow/app.h index 7424da068..0ce9b5b7e 100644 --- a/include/crow/app.h +++ b/include/crow/app.h @@ -563,15 +563,14 @@ namespace crow else #endif { - close_websockets(websockets_); + close_websockets(); if (server_) { server_->stop(); } } } - void close_websockets(const std::vector& websockets) + void close_websockets() { - std::vector websockets_to_close = websockets; - for (auto websocket : websockets_to_close) + for (auto websocket : websockets_) { CROW_LOG_INFO << "Quitting Websocket: " << websocket; websocket->close("Websocket Closed");