App.closeSockets

This commit is contained in:
Alex Hultman
2022-12-28 05:38:34 +01:00
parent 16126902c2
commit c603228a69
2 changed files with 16 additions and 1 deletions
+15
View File
@@ -85,6 +85,8 @@ private:
/* WebSocketContexts are of differing type, but we as owners and creators must delete them correctly */
std::vector<MoveOnlyFunction<void()>> webSocketContextDeleters;
std::vector<void *> webSocketContexts;
public:
TopicTree<TopicTreeMessage, TopicTreeBigMessage> *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<void(WebSocket<SSL, true, UserData> *, 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 <typename UserData>
TemplatedApp &&ws(std::string pattern, WebSocketBehavior<UserData> &&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;