diff --git a/include/crow/app.h b/include/crow/app.h index 9e89a1342..0ce9b5b7e 100644 --- a/include/crow/app.h +++ b/include/crow/app.h @@ -563,17 +563,21 @@ 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"); - } + close_websockets(); if (server_) { server_->stop(); } } } + void close_websockets() + { + for (auto websocket : websockets_) + { + 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 d364ba2d6..5f336d5bc 100644 --- a/include/crow/http_server.h +++ b/include/crow/http_server.h @@ -251,6 +251,7 @@ namespace crow // NOTE: Already documented in "crow/app.h" io_context_.stop(); // Close main io_service } + uint16_t port() const { return acceptor_.local_endpoint().port(); }