-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (55 loc) · 1.23 KB
/
main.cpp
File metadata and controls
62 lines (55 loc) · 1.23 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
57
58
59
60
61
62
#include <iostream>
#include <unistd.h>
#include <getopt.h>
#include <stdlib.h>
#include <stdio.h>
#include <boost/asio.hpp>
#include "server.h"
using namespace std;
int main(int argc, char** argv) {
cout << "Hello, World!" << endl;
std::string ip;
std::string path;
// int port = 0;
std::string port;
int option = 0;
while ((option = getopt(argc, argv, "h:p:d:")) != -1)
{
switch (option) {
case 'h' : {
ip = optarg;
break;
}
case 'p' : {
port = optarg;
break;
}
case 'd' : {
path = optarg;
break;
}
default:
exit(EXIT_FAILURE);
}
}
cout << "port: " << port << endl;
cout << "ip: " << ip << endl;
cout << "path: " << path << endl;
pid_t pid = fork();
if (pid < 0)
return 1;
if (pid > 0)
return 0;
pid_t sid = setsid();
if (sid < 0)
return 2;
if (chdir("/") < 0)
return 3;
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
http::server::server s(ip, port, path);
s.run();
// pause();
return 0;
}