forked from jserv/facebooc
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.c
42 lines (33 loc) · 884 Bytes
/
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
#include <signal.h>
#include <stdio.h>
#include "facebooc_server.h"
static void sig(int signum);
Facebooc *fb;
int main(int argc, char *argv[])
{
if (signal(SIGINT, sig) == SIG_ERR || signal(SIGTERM, sig) == SIG_ERR) {
fprintf(stderr, "error: failed to bind signal handler\n");
return 1;
}
uint16_t server_port = 8080;
if (argc > 1 && sscanf(argv[1], "%hu", &server_port) == 0) {
fprintf(stderr,
"error: invalid command line argument, using default port "
"8080.\n");
server_port = 8080;
}
fb = FB_new(server_port);
int res = FB_run(fb);
if (res) {
// Do some error handling
fprintf(stderr, "Stop fb server.\n");
}
FB_delete(fb);
return 0;
}
static void sig(int signum)
{
FB_delete(fb);
fprintf(stdout, "\n[%d] Bye!\n", signum);
exit(0);
}