mirror of
https://github.com/modelec/TCPSocketServer.git
synced 2026-01-19 00:47:36 +01:00
handle the SIGTERM, now stop the the thread of the game
This commit is contained in:
15
main.cpp
15
main.cpp
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user