Last active
April 25, 2020 12:53
-
-
Save alexcohn/c7f1d215fd2f1f904dc864e1ba881f2f to your computer and use it in GitHub Desktop.
try to shut down the Loop with uWebSockets v.0.17.4 (see https://github.com/uNetworking/uWebSockets/issues/809#issuecomment-619246807)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "App.h" | |
using namespace std::chrono_literals; | |
using namespace std::chrono; | |
#include "../uSockets/src/internal/eventing/epoll_kqueue.h" | |
/* Note that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support */ | |
int main() { | |
us_listen_socket_t * listenSocket = nullptr; | |
auto before = steady_clock::now(); | |
/* Overly simple hello world app */ | |
uWS::SSLApp({ | |
.key_file_name = "../misc/key.pem", | |
.cert_file_name = "../misc/cert.pem", | |
.passphrase = "1234" | |
}).get("/*", [&listenSocket, &before](auto *res, auto *req) { | |
res->end("hi there"); | |
std::cout << req->getUrl() << std::endl; | |
if (req->getUrl()[1] == 'q') { | |
auto loop = reinterpret_cast<us_loop_t*>(uWS::Loop::get()); | |
std::cout << "will shutdown " << loop << std::endl; | |
std::thread shutdown([&listenSocket, &before, loop] { | |
std::cout << "yes, will shutdown" << std::endl; | |
std::this_thread::sleep_for(200ms); | |
std::cout << "shutting down " << listenSocket << " " << loop->num_polls << std::endl; | |
before = steady_clock::now(); | |
loop->num_polls = 0; | |
us_wakeup_loop(loop); | |
}); | |
shutdown.detach(); | |
} | |
}).listen(3000, [&listenSocket](auto *token) { | |
if (token) { | |
std::cout << "token " << token << std::endl; | |
std::cout << "Listening on port " << 3000 << std::endl; | |
} | |
listenSocket = token; | |
}).run(); | |
std::cout << "finished in " << duration_cast<milliseconds>(steady_clock::now() - before).count() << "ms" << std::endl; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "App.h" | |
using namespace std::chrono_literals; | |
using namespace std::chrono; | |
/* Note that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support */ | |
int main() { | |
us_listen_socket_t * listenSocket = nullptr; | |
auto before = steady_clock::now(); | |
/* Overly simple hello world app */ | |
uWS::SSLApp({ | |
.key_file_name = "../misc/key.pem", | |
.cert_file_name = "../misc/cert.pem", | |
.passphrase = "1234" | |
}).get("/*", [&listenSocket, &before](auto *res, auto *req) { | |
res->end("hi there"); | |
std::cout << req->getUrl() << std::endl; | |
if (req->getUrl()[1] == 'q') { | |
std::cout << "will shutdown" << std::endl; | |
std::thread shutdown([&listenSocket, &before] { | |
std::cout << "yes, will shutdown" << std::endl; | |
std::this_thread::sleep_for(200ms); | |
std::cout << "shutting down " << listenSocket << std::endl; | |
before = steady_clock::now(); | |
us_listen_socket_close(1, listenSocket); | |
std::cout << "closed in " << duration_cast<milliseconds>(steady_clock::now() - before).count() << "ms" << std::endl; | |
}); | |
shutdown.detach(); | |
} | |
}).listen(3000, [&listenSocket](auto *token) { | |
if (token) { | |
std::cout << "token " << token << std::endl; | |
std::cout << "Listening on port " << 3000 << std::endl; | |
} | |
listenSocket = token; | |
}).run(); | |
std::cout << "finished in " << duration_cast<milliseconds>(steady_clock::now() - before).count() << "ms" << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment