From 98cef5e9a772602d42acfcf233838c760424db9a Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Thu, 13 Feb 2025 18:00:17 +1100 Subject: initial commit --- comp3331/server/src/shared/shared.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 comp3331/server/src/shared/shared.cc (limited to 'comp3331/server/src/shared/shared.cc') diff --git a/comp3331/server/src/shared/shared.cc b/comp3331/server/src/shared/shared.cc new file mode 100644 index 0000000..3a13b47 --- /dev/null +++ b/comp3331/server/src/shared/shared.cc @@ -0,0 +1,25 @@ +#include "shared/shared.hh" + +namespace shared { + +bool should_exit = false; + +static void set_signal(const decltype(SIGINT) signal, + void (*const callback)(const int)) { + struct sigaction sa {}; + sa.sa_handler = callback; + if (sigaction(signal, &sa, nullptr) == -1) { + throw std::runtime_error("failed to set signal handler!"); + } +} + +void set_exit_handler() { + set_signal(SIGPIPE, SIG_IGN); + set_signal(SIGINT, [](const int) { + std::cout << " interrupt signal received\n"; + should_exit = true; + }); +} + +} // namespace shared + -- cgit v1.2.3