Update threaded example
This commit is contained in:
@@ -3,7 +3,9 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
std::mutex m;
|
/* Note that SSL is disabled unless you build with WITH_OPENSSL=1 */
|
||||||
|
const int SSL = 1;
|
||||||
|
std::mutex stdoutMutex;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
/* Overly simple hello world app, using multiple threads */
|
/* Overly simple hello world app, using multiple threads */
|
||||||
@@ -12,16 +14,21 @@ int main() {
|
|||||||
std::transform(threads.begin(), threads.end(), threads.begin(), [](std::thread */*t*/) {
|
std::transform(threads.begin(), threads.end(), threads.begin(), [](std::thread */*t*/) {
|
||||||
return new std::thread([]() {
|
return new std::thread([]() {
|
||||||
|
|
||||||
uWS::App().get("/*", [](auto *res, auto * /*req*/) {
|
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!");
|
res->end("Hello world!");
|
||||||
}).listen(3000, [](auto *listen_socket) {
|
}).listen(3000, [](auto *listen_socket) {
|
||||||
m.lock();
|
stdoutMutex.lock();
|
||||||
if (listen_socket) {
|
if (listen_socket) {
|
||||||
std::cout << "Thread " << std::this_thread::get_id() << " listening on port " << 3000 << std::endl;
|
/* 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 {
|
} else {
|
||||||
std::cout << "Thread " << std::this_thread::get_id() << " failed to listen on port 3000" << std::endl;
|
std::cout << "Thread " << std::this_thread::get_id() << " failed to listen on port 3000" << std::endl;
|
||||||
}
|
}
|
||||||
m.unlock();
|
stdoutMutex.unlock();
|
||||||
}).run();
|
}).run();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user