-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
51 lines (47 loc) · 1.2 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
#include "httpserver.h"
#include <unistd.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <exception>
int main(int argc, char **argv)
{
int port = 0;
int nCPU = 0;
char* rootDir = 0;
int c = 0;
while ((c = getopt (argc, argv, "p:n:r:")) != -1) {
switch(c) {
case 'p':
port = atoi(optarg);
if(port < 1 || port > 65535) {
std::cout << "Wrong port: " << port << std::endl;
return 0;
}
break;
case 'n':
nCPU = atoi(optarg);
if(nCPU < 1) {
std::cout << "Wrong nCPU: " << nCPU << std::endl;
return 0;
}
break;
case 'r':
rootDir = optarg;
if(rootDir[strlen(rootDir) - 1] == '/') {
rootDir[strlen(rootDir) - 1] = '\0';
}
break;
}
}
HttpServer* httpServer = 0;
try {
HttpServer* httpServer = new HttpServer();
httpServer->startServer(port, nCPU, rootDir);
}
catch(std::exception& err) {
std::cout << err.what() << std::endl;
}
delete httpServer;
return 0;
}