-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
108 lines (88 loc) · 2.08 KB
/
main.c
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "macnockserver.h"
#include "macnockclient.h"
#include "macstorage.h"
#include "log.h"
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
const int PORT = 2342;
const uint8_t VERSION = 1;
const char *g_interface;
const char *g_hood;
void sigHandler(int sig)
{
(void)sig;
macNockServer_stop();
macNockClient_stop();
macStorage_stop();
}
void* serverRoutine(void *arg)
{
macNockServer_run();
return arg;
}
void* clientRoutine(void *arg)
{
macNockClient_run();
return arg;
}
void* storageRoutine(void *arg)
{
macStorage_run();
return arg;
}
int main(int argc, char *argv[])
{
if (argc < 3)
{
printf("Send and listen for nock requests\n");
printf("\n");
printf("%s interface code command\n", argv[0]);
printf("Example:\n");
printf("%s eth0.3 \"FuerthV2\"\n", argv[0]);
return -1;
}
g_interface = argv[1];
g_hood = argv[2];
printf("%s: Running for hood %s on interface %s\n", argv[0], g_hood, g_interface);
signal(SIGINT, &sigHandler);
signal(SIGTERM, &sigHandler);
pthread_t serverThread;
pthread_t clientThread;
pthread_t storageThread;
if (pthread_create(&serverThread, NULL, serverRoutine, NULL))
{
fprintf(stderr, "Error creating thread\n");
return 1;
}
if (pthread_create(&clientThread, NULL, clientRoutine, NULL))
{
fprintf(stderr, "Error creating thread\n");
return 1;
}
if (pthread_create(&storageThread, NULL, storageRoutine, NULL))
{
fprintf(stderr, "Error creating thread\n");
return 1;
}
if (pthread_join(serverThread, NULL))
{
fprintf(stderr, "Error joining thread\n");
return 2;
}
if (pthread_join(clientThread, NULL))
{
fprintf(stderr, "Error joining thread\n");
return 2;
}
if (pthread_join(storageThread, NULL))
{
fprintf(stderr, "Error joining thread\n");
return 2;
}
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
return 0;
}