-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
55 lines (49 loc) · 1.01 KB
/
main.cpp
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
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <linux/fs.h>
#include <stdio.h>
#include <fcntl.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <boost/asio.hpp>
#include "server.hpp"
#include "threadpool.hpp"
int main(int argc, char* argv[])
{
try
{
int opt = 0;
std::string addr;
std::string port;
std::string dir;
while ((opt = getopt(argc, argv, "hpd")) != -1) {
switch (opt) {
case 'h':
addr = argv[optind];
break;
case 'p':
port = argv[optind];
break;
case 'd':
dir = argv[optind];
break;
default: /* '?' */
exit(EXIT_FAILURE);
}
}
if (daemon(0, 0) == -1) {
return -1;
}
thread_pool pool(boost::thread::hardware_concurrency());
// Initialise the server.
http::server::server s(pool.get_io_service(), addr, port, dir);
// Run the server until stopped.
pause();
}
catch (std::exception& e)
{
}
return 0;
}