-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
47 lines (35 loc) · 820 Bytes
/
main.c
File metadata and controls
47 lines (35 loc) · 820 Bytes
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 "map_html_util.h"
#include "server.h"
#include <assert.h>
#include <map.h>
#include <signal.h>
#include <stdio.h>
volatile sig_atomic_t endSession = 0;
map *m;
void clean_up() { map_delete(m); }
void handle_sigint(int sig) {
assert(sig == SIGINT);
endSession = 1;
}
int main(int argc, char **argv) {
if (argc != 3) {
fprintf(stderr, "usage: ./server <port> <folder to website>\n");
exit(1);
}
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handle_sigint;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGINT, &sa, NULL) == -1) {
perror("sigaction");
return 1;
}
m = create_map();
map_html_files(m, argv[2], "");
char *port = argv[1];
int socket_fd = create_server(port);
run_server(socket_fd);
clean_up();
return 0;
}