-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy paths5.c
47 lines (37 loc) · 840 Bytes
/
s5.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
#include <stdlib.h>
#include <unistd.h>
#include "s5_dns_resolver.h"
#include "s5_server.h"
#include "s5_signal.h"
#include "s5_util.h"
static int parse_args(int argc, char** argv, int* port) {
if (argc != 2) {
return -1;
}
*port = atoi(argv[1]);
return 0;
}
// https://tools.ietf.org/rfc/rfc1928
int main(int argc, char** argv) {
int err, port;
err = parse_args(argc, argv, &port);
if (err) {
printf("Usage: %s <port>\n", *argv);
return -1;
}
s5_signal_init();
s5_epoll_t* ep = s5_epoll_create();
assert(ep);
s5_server_t* s = s5_server_create(port, ep);
assert(s);
err = s5_dns_resolver_start(s, ep);
assert(!err);
err = s5_server_start(s, ep);
if (err) {
perror_and_exit("s5_server_start");
}
s5_epoll_run(ep);
// TODO destory other?
s5_epoll_destroy(ep);
return 0;
}