From a2ddfe6913c1884bfef6314d00cf2b708281ff79 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Mon, 28 Aug 2023 08:38:30 -0700 Subject: Bring uSockets & uWebSockets forks into Bun's repository (#4372) * Move uWebSockets and uSockets forks into Bun's repository * Update Makefile * Update settings.json * Update libuwsockets.cpp * Remove backends we won't be using * Update bindings.cpp --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> --- packages/bun-uws/examples/HelloWorldThreaded.cpp | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 packages/bun-uws/examples/HelloWorldThreaded.cpp (limited to 'packages/bun-uws/examples/HelloWorldThreaded.cpp') diff --git a/packages/bun-uws/examples/HelloWorldThreaded.cpp b/packages/bun-uws/examples/HelloWorldThreaded.cpp new file mode 100644 index 000000000..e4d871f65 --- /dev/null +++ b/packages/bun-uws/examples/HelloWorldThreaded.cpp @@ -0,0 +1,40 @@ +#include "App.h" +#include +#include +#include + +/* Note that SSL is disabled unless you build with WITH_OPENSSL=1 */ +const int SSL = 1; +std::mutex stdoutMutex; + +int main() { + /* Overly simple hello world app, using multiple threads */ + std::vector threads(std::thread::hardware_concurrency()); + + std::transform(threads.begin(), threads.end(), threads.begin(), [](std::thread */*t*/) { + return new std::thread([]() { + + uWS::SSLApp({ + .key_file_name = "misc/key.pem", + .cert_file_name = "misc/cert.pem", + .passphrase = "1234" + }).get("/*", [](auto *res, auto * /*req*/) { + res->end("Hello world!"); + }).listen(3000, [](auto *listen_socket) { + stdoutMutex.lock(); + if (listen_socket) { + /* Note that us_listen_socket_t is castable to us_socket_t */ + std::cout << "Thread " << std::this_thread::get_id() << " listening on port " << us_socket_local_port(SSL, (struct us_socket_t *) listen_socket) << std::endl; + } else { + std::cout << "Thread " << std::this_thread::get_id() << " failed to listen on port 3000" << std::endl; + } + stdoutMutex.unlock(); + }).run(); + + }); + }); + + std::for_each(threads.begin(), threads.end(), [](std::thread *t) { + t->join(); + }); +} -- cgit v1.2.3