mirror of
https://github.com/modelec/servo_moteurs.git
synced 2026-03-18 21:40:31 +01:00
Add SIGINT and SIGTERM handle
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -125,3 +125,4 @@ fabric.properties
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
.idea
|
||||
|
||||
24
main.cpp
24
main.cpp
@@ -1,6 +1,16 @@
|
||||
#include "MyTCPClient.h"
|
||||
#include <atomic>
|
||||
#include <csignal>
|
||||
|
||||
std::atomic<bool> shouldStop = false;
|
||||
|
||||
void signalHandler( int signum ) {
|
||||
shouldStop = true;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
signal(SIGINT, signalHandler);
|
||||
signal(SIGTERM, signalHandler);
|
||||
int port = 8080;
|
||||
if (argc > 1) {
|
||||
port = std::stoi(argv[1]);
|
||||
@@ -8,12 +18,18 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
MyTCPClient client("127.0.0.1", port);
|
||||
|
||||
client.start();
|
||||
try{
|
||||
client.start();
|
||||
|
||||
client.sendMessage("servo_moteur;strat;ready;1");
|
||||
while(!client.shouldStop()){
|
||||
usleep(100'000);
|
||||
}
|
||||
|
||||
while (!client.shouldStop()) {
|
||||
usleep(100'000);
|
||||
client.sendMessage("servo_moteur;strat;ready;1");
|
||||
}
|
||||
catch (const std::exception& e){
|
||||
std::cerr << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user