Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Start server after register signal handler
  • Loading branch information
mtrenkmann committed Nov 20, 2018
commit 9080adac454356d62c416853f3fb6310faf8e0c9
7 changes: 6 additions & 1 deletion libs/network/example/http/echo_async_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,21 @@ int main() {
auto io_service = std::make_shared<boost::asio::io_service>();
echo_server server(
echo_server::options(handler).io_service(io_service).port("8000"));
server.run();

// Clean shutdown when pressing Ctrl+C.
boost::asio::signal_set signals(*io_service, SIGINT, SIGTERM);
signals.async_wait([&server](const boost::system::error_code& ec,
int /* signal_number */) {
if (!ec) {
std::cout << "Stopping server... ";
server.stop();
std::cout << "done.\n";
}
});

std::cout << "Press Ctrl+C to stop the server.\n";
server.run();

return EXIT_SUCCESS;
} catch (const std::exception& error) {
std::cerr << error.what() << std::endl;
Expand Down