-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (46 loc) · 1.15 KB
/
Copy pathmain.cpp
File metadata and controls
56 lines (46 loc) · 1.15 KB
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
#include <iostream>
#include <string>
#include <unistd.h>
#include "server.hpp"
#define NUM_THREADS 4
struct Config
{
std::string ip;
std::string port;
std::string dir;
};
Config GetConfig(int argc, char**argv)
{
const std::string optStr = "h:p:d:";
Config config;
auto opt = getopt( argc, argv, optStr.c_str());
while( opt != -1 ) {
switch( opt ) {
case 'h':
config.ip = optarg;
break;
case 'p':
config.port = optarg;
break;
case 'd':
config.dir = optarg;
break;
}
opt = getopt( argc, argv, optStr.c_str());
}
std::cout << "ip: " << config.ip
<< "; port: " << config.port
<< "; dir: " << config.dir << std::endl;
return config;
}
int main (int argc, char ** argv)
{
auto cfg = GetConfig(argc, argv);
if(fork() == 0)
{
std::cout << "daemon started" << std::endl;
http::server3::server s(cfg.ip, cfg.port, cfg.dir, NUM_THREADS);
s.run();
}
return 0;
}