-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathda_proc.cpp
More file actions
83 lines (57 loc) · 1.53 KB
/
da_proc.cpp
File metadata and controls
83 lines (57 loc) · 1.53 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
75
76
77
78
79
80
81
82
83
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <time.h>
#include <thread>
#include <iostream>
#include "Manager.h"
#include "utilities.h"
using namespace std;
static int wait_for_start = 1;
bool initialization_phase = true;
static void start(int signum) {
cout << signum << " received" << endl;
wait_for_start = 0;
initialization_phase = false;
}
static void stop(int signum) {
//reset signal handlers to default
signal(SIGTERM, SIG_DFL);
signal(SIGINT, SIG_DFL);
//immediately stop network packet processing
printf("Immediately stopping network packet processing.\n");
//write/flush output file if necessary
printf("Writing output.\n");
//exit directly from signal handler
exit(0);
}
int main(int argc, char** argv) {
//set signal handlers
signal(SIGUSR2, start);
signal(SIGTERM, stop);
signal(SIGINT, stop);
//parse arguments, including membership
//initialize application
//start listening for incoming UDP packets
printf("Initializing.\n");
cout << "The process id is " << ::getpid() << endl;
// Here we must initialize everything!
Manager* manager = parse_input_data(argc, argv);
//wait until start signal
while(wait_for_start) {
struct timespec sleep_time;
sleep_time.tv_sec = 0;
sleep_time.tv_nsec = 1000;
nanosleep(&sleep_time, NULL);
}
//broadcast messages
printf("Broadcasting messages.\n");
//wait until stopped
manager->run();
while(1) {
struct timespec sleep_time;
sleep_time.tv_sec = 1;
sleep_time.tv_nsec = 0;
nanosleep(&sleep_time, NULL);
}
}