First commit
This commit is contained in:
parent
2394cc7845
commit
12910fd7b6
|
@ -0,0 +1,12 @@
|
|||
#ifndef SIGNAL_H
|
||||
#define SIGNAL_H
|
||||
|
||||
#define DEFAULT_SIGINT 2
|
||||
#define TIME_TO_RESET 30
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
void serverSigHandler(int sig);
|
||||
void setServerSignalHandler();
|
||||
|
||||
#endif
|
|
@ -0,0 +1,28 @@
|
|||
#include <unistd.h>
|
||||
#include "../inc/custom_signal.h"
|
||||
|
||||
void serverSigHandler(int sig) {
|
||||
static int sigint_count = DEFAULT_SIGINT;
|
||||
|
||||
switch (sig) {
|
||||
case SIGINT:
|
||||
sigint_count--;
|
||||
if (sigint_count > 0) {
|
||||
printf("<Server> Press again Ctrl^C to exit (whitin %d sec)\n", TIME_TO_RESET);
|
||||
alarm(TIME_TO_RESET);
|
||||
} else {
|
||||
// TODO bisogna fare un "at exit"
|
||||
exit(0);
|
||||
}
|
||||
break;
|
||||
default: //SIGALRM
|
||||
printf("<Server> Time to exit (%d s) expired", TIME_TO_RESET);
|
||||
sigint_count = DEFAULT_SIGINT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setServerSignalHandler() {
|
||||
signal(SIGINT, serverSigHandler);
|
||||
signal(SIGALRM, serverSigHandler);
|
||||
}
|
Loading…
Reference in New Issue