From c603228a69c0040374af4775e345c5b1f8501647 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Wed, 28 Dec 2022 05:38:34 +0100 Subject: [PATCH] App.closeSockets --- src/App.h | 15 +++++++++++++++ uSockets | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/App.h b/src/App.h index 725f7f5a0..a6b7da041 100644 --- a/src/App.h +++ b/src/App.h @@ -85,6 +85,8 @@ struct TemplatedApp { /* WebSocketContexts are of differing type, but we as owners and creators must delete them correctly */ std::vector> webSocketContextDeleters; + std::vector webSocketContexts; + public: TopicTree *topicTree = nullptr; @@ -205,6 +207,8 @@ struct TemplatedApp { /* Move webSocketContextDeleters */ webSocketContextDeleters = std::move(other.webSocketContextDeleters); + webSocketContexts = std::move(other.webSocketContexts); + /* Move TopicTree */ topicTree = other.topicTree; other.topicTree = nullptr; @@ -245,6 +249,14 @@ struct TemplatedApp { MoveOnlyFunction *, int, std::string_view)> close = nullptr; }; + /* Closes all sockets. Does not close listen sockets. */ + TemplatedApp &&closeSockets() { + us_socket_context_close(SSL, httpContext); + for (void *webSocketContext : webSocketContexts) { + us_socket_context_close(SSL, webSocketContext); + } + } + template TemplatedApp &&ws(std::string pattern, WebSocketBehavior &&behavior) { /* Don't compile if alignment rules cannot be satisfied */ @@ -335,6 +347,9 @@ struct TemplatedApp { webSocketContext->free(); }); + /* We also keep this list for easy closing */ + webSocketContexts.push_back((void *)webSocketContext); + /* Quick fix to disable any compression if set */ #ifdef UWS_NO_ZLIB behavior.compression = DISABLED; diff --git a/uSockets b/uSockets index 6e9d3c880..afd527a99 160000 --- a/uSockets +++ b/uSockets @@ -1 +1 @@ -Subproject commit 6e9d3c880de6a6827c75825adcfaf0e0cb16cced +Subproject commit afd527a99c427b19f4441855f47c1340ed9962ea