From cd92fcf2ea8e62623aa231adb9244724a34cf0eb Mon Sep 17 00:00:00 2001 From: partyblob <115790365+partyblob@users.noreply.github.com> Date: Sat, 29 Jun 2024 10:53:55 +0100 Subject: [PATCH 1/5] Remove unnecessary lambda --- src/App.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/App.h b/src/App.h index f0e2a4dc3..0ed923ce6 100644 --- a/src/App.h +++ b/src/App.h @@ -382,14 +382,7 @@ struct TemplatedApp { webSocketContext->getExt()->droppedHandler = std::move(behavior.dropped); webSocketContext->getExt()->drainHandler = std::move(behavior.drain); webSocketContext->getExt()->subscriptionHandler = std::move(behavior.subscription); - webSocketContext->getExt()->closeHandler = std::move([closeHandler = std::move(behavior.close)](WebSocket *ws, int code, std::string_view message) mutable { - if (closeHandler) { - closeHandler(ws, code, message); - } - - /* Destruct user data after returning from close handler */ - ((UserData *) ws->getUserData())->~UserData(); - }); + webSocketContext->getExt()->closeHandler = std::move(behavior.close); webSocketContext->getExt()->pingHandler = std::move(behavior.ping); webSocketContext->getExt()->pongHandler = std::move(behavior.pong); From 312f7d1c76591ebee58a3be3d4c6da8bc7ddf6b2 Mon Sep 17 00:00:00 2001 From: partyblob <115790365+partyblob@users.noreply.github.com> Date: Sat, 29 Jun 2024 10:54:37 +0100 Subject: [PATCH 2/5] Free userdata here instead --- src/WebSocket.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/WebSocket.h b/src/WebSocket.h index ba11281d8..a433e9d4f 100644 --- a/src/WebSocket.h +++ b/src/WebSocket.h @@ -241,6 +241,7 @@ struct WebSocket : AsyncSocket { if (webSocketContextData->closeHandler) { webSocketContextData->closeHandler(this, code, message); } + ((USERDATA *) this->getUserData())->~USERDATA(); } /* Corks the response if possible. Leaves already corked socket be. */ From 3fc21c5b64d073a2eec7f60527a46a2cff2cae65 Mon Sep 17 00:00:00 2001 From: partyblob <115790365+partyblob@users.noreply.github.com> Date: Sat, 29 Jun 2024 10:55:35 +0100 Subject: [PATCH 3/5] Free userdata here instead --- src/WebSocketContext.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/WebSocketContext.h b/src/WebSocketContext.h index c49a6ac96..94af437d3 100644 --- a/src/WebSocketContext.h +++ b/src/WebSocketContext.h @@ -269,9 +269,11 @@ struct WebSocketContext { webSocketContextData->topicTree->freeSubscriber(webSocketData->subscriber); webSocketData->subscriber = nullptr; + auto *ws = (WebSocket *) s; if (webSocketContextData->closeHandler) { - webSocketContextData->closeHandler((WebSocket *) s, 1006, {(char *) reason, (size_t) code}); + webSocketContextData->closeHandler(ws, 1006, {(char *) reason, (size_t) code}); } + ((USERDATA *) ws->getUserData())->~USERDATA(); } /* Destruct in-placed data struct */ From 3b301b349a5e88531b1e0be756e2f211ddfd5e91 Mon Sep 17 00:00:00 2001 From: BlobTheKat Date: Wed, 23 Oct 2024 13:39:32 +0100 Subject: [PATCH 4/5] Bump for uSockets#231 --- src/App.h | 13 ++++++++----- src/Http3App.h | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/App.h b/src/App.h index 57cd04276..e7e3e00fe 100644 --- a/src/App.h +++ b/src/App.h @@ -61,13 +61,16 @@ namespace uWS { /* This one matches us_socket_context_options_t but has default values */ struct SocketContextOptions { - const char *key_file_name = nullptr; - const char *cert_file_name = nullptr; + union{ const char *key_file_name = nullptr, *key_file; }; + union{ const char *cert_file_name = nullptr, *cert_file; }; const char *passphrase = nullptr; - const char *dh_params_file_name = nullptr; - const char *ca_file_name = nullptr; + union{ const char *dh_params_file_name = nullptr, *dh_params_file; }; + union{ const char *ca_file_name = nullptr, *ca_file; }; const char *ssl_ciphers = nullptr; - int ssl_prefer_low_memory_usage = 0; + char ssl_prefer_low_memory_usage = 0; + char key_data_inline = 0; + char cert_data_inline = 0; + char dh_params_data_inline = 0; /* Conversion operator used internally */ operator struct us_socket_context_options_t() const { diff --git a/src/Http3App.h b/src/Http3App.h index 4c54b2955..625c64e73 100644 --- a/src/Http3App.h +++ b/src/Http3App.h @@ -16,6 +16,8 @@ namespace uWS { h3options.key_file_name = strdup(options.key_file_name); h3options.cert_file_name = strdup(options.cert_file_name); h3options.passphrase = strdup(options.passphrase); + h3options.key_data_inline = options.key_data_inline; + h3options.cert_data_inline = options.cert_data_inline; /* Create the http3 context */ http3Context = Http3Context::create((us_loop_t *)Loop::get(), h3options); From 50378a37357673d87f41336cb16f890e0a85494f Mon Sep 17 00:00:00 2001 From: BlobTheKat Date: Wed, 23 Oct 2024 14:19:32 +0100 Subject: [PATCH 5/5] setOptions() --- src/App.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/App.h b/src/App.h index e7e3e00fe..e3d922b56 100644 --- a/src/App.h +++ b/src/App.h @@ -96,6 +96,14 @@ struct TemplatedAppBase { TopicTree *topicTree = nullptr; + BuilderPatternReturnType &&setOptions(const SocketContextOptions& options) { + + /* Options might be more than just SSL in the future */ + us_update_socket_context(SSL, (struct us_socket_context_t *) httpContext, (const struct us_socket_context_options_t*) &options); + + return std::move(static_cast(*this)); + } + /* Server name */ BuilderPatternReturnType &&addServerName(std::string hostname_pattern, SocketContextOptions options = {}) {