Created
December 3, 2018 22:54
-
-
Save vinniefalco/c723b10eccefa74bc179df688a7fbcc8 to your computer and use it in GitHub Desktop.
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
// Capture SIGINT and SIGTERM to perform a clean shutdown | |
net::signal_set signals(ioc, SIGINT, SIGTERM); | |
signals.async_wait( | |
[&](beast::error_code const&, int) | |
{ | |
// Stop the `io_context`. This will cause `run()` | |
// to return immediately, eventually destroying the | |
// `io_context` and all of the sockets in it. | |
ioc.stop(); | |
}); | |
// Run the I/O service on the requested number of threads | |
std::vector<std::thread> v; | |
v.reserve(threads - 1); | |
for(auto i = threads - 1; i > 0; --i) | |
v.emplace_back( | |
[&ioc] | |
{ | |
ioc.run(); | |
}); | |
ioc.run(); | |
// (If we get here, it means we got a SIGINT or SIGTERM) | |
// Block until all the threads exit | |
for(auto& t : v) | |
t.join(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment