-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathservermain.cpp
More file actions
74 lines (47 loc) · 1.52 KB
/
Copy pathservermain.cpp
File metadata and controls
74 lines (47 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/time.h>
/* You will to add includes here */
// Included to get the support library
#include <calcLib.h>
#include "protocol.h"
using namespace std;
/* Needs to be global, to be rechable by callback and main */
int loopCount=0;
int terminate=0;
/* Call back function, will be called when the SIGALRM is raised when the timer expires. */
void checkJobbList(int signum){
// As anybody can call the handler, its good coding to check the signal number that called it.
printf("Let me be, I want to sleep, loopCount = %d.\n", loopCount);
if(loopCount>20){
printf("I had enough.\n");
terminate=1;
}
return;
}
int main(int argc, char *argv[]){
/* Do more magic */
/*
Prepare to setup a reoccurring event every 10s. If it_interval, or it_value is omitted, it will be a single alarm 10s after it has been set.
*/
struct itimerval alarmTime;
alarmTime.it_interval.tv_sec=10;
alarmTime.it_interval.tv_usec=10;
alarmTime.it_value.tv_sec=10;
alarmTime.it_value.tv_usec=10;
/* Regiter a callback function, associated with the SIGALRM signal, which will be raised when the alarm goes of */
signal(SIGALRM, checkJobbList);
setitimer(ITIMER_REAL,&alarmTime,NULL); // Start/register the alarm.
#ifdef DEBUG
printf("DEBUGGER LINE ");
#endif
while(terminate==0){
printf("This is the main loop, %d time.\n",loopCount);
sleep(1);
loopCount++;
}
printf("done.\n");
return(0);
}