Skip to content

Commit

Permalink
Process terminator signal
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackarain committed Nov 10, 2023
1 parent 22216bf commit e127907
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions server/proxy_server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <boost/asio/io_context.hpp>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/signal_set.hpp>

#include <boost/algorithm/string/join.hpp>
#include <boost/program_options.hpp>
Expand Down Expand Up @@ -289,8 +290,25 @@ int main(int argc, char** argv)
LOG_DBG << "Start server: " << server_listen;

net::io_context ioc(1);
net::signal_set terminator_signal(ioc);
server_ptr server;

terminator_signal.add(SIGINT);
terminator_signal.add(SIGTERM);
#ifdef __linux__
signal(SIGPIPE, SIG_IGN);
#endif
#if defined(SIGQUIT)
terminator_signal.add(SIGQUIT);
#endif // defined(SIGQUIT)

terminator_signal.async_wait(
[&](const boost::system::error_code&, int sig) mutable
{
terminator_signal.remove(sig);
ioc.stop();
});

net::co_spawn(ioc,
start_proxy_server(ioc, server),
net::detached);
Expand Down

0 comments on commit e127907

Please sign in to comment.