handle the SIGTERM, now stop the the thread of the game

This commit is contained in:
ackimixs
2024-04-19 10:55:26 +02:00
parent e82930bd29
commit f4efd38059
3 changed files with 26 additions and 211 deletions

View File

@@ -1,6 +1,17 @@
#include "TCPServer.h"
#include <csignal>
std::atomic<bool> shouldStop = false;
void signalHandler( int signum ) {
shouldStop = true;
exit(signum);
}
int main(int argc, char* argv[]) {
signal(SIGINT, signalHandler);
int port = 8080;
if (argc >= 2) {
@@ -12,8 +23,8 @@ int main(int argc, char* argv[]) {
try {
server.start();
while (!server.shouldStop()) {
usleep(1'000'000);
while (!server.shouldStop() && !shouldStop) {
usleep(500'000);
}
server.stop();