diff --git a/src/App.h b/src/App.h index 725f7f5..a6b7da0 100644 --- a/src/App.h +++ b/src/App.h @@ -85,6 +85,8 @@ private: /* 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 @@ public: /* Move webSocketContextDeleters */ webSocketContextDeleters = std::move(other.webSocketContextDeleters); + webSocketContexts = std::move(other.webSocketContexts); + /* Move TopicTree */ topicTree = other.topicTree; other.topicTree = nullptr; @@ -245,6 +249,14 @@ public: 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 @@ public: 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 6e9d3c8..afd527a 160000 --- a/uSockets +++ b/uSockets @@ -1 +1 @@ -Subproject commit 6e9d3c880de6a6827c75825adcfaf0e0cb16cced +Subproject commit afd527a99c427b19f4441855f47c1340ed9962ea