-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
45 lines (41 loc) · 790 Bytes
/
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
#include "EventLoop.h"
#include "Server.h"
// #include "base/Logging.h"
#include <getopt.h>
#include <string>
int main(int argc,char* argv[])
{
int threadNum = 4;
int port = 80;
std::string logPath = "./WebServer.log";
// parse args
int opt;
const char* str = "t:l:p";
while ((opt = getopt(argc, argv, str)) != -1) {
switch (opt) {
case 't': {
threadNum = atoi(optarg);
break;
}
case 'l': {
logPath = optarg;
if (logPath.size() < 2 || optarg[0] != '/') {
printf("logPath should start with \"/\" \n");
abort();
}
break;
}
case 'p': {
port = atoi(optarg);
break;
}
default:
break;
}
}
EventLoop mainLoop;
Server myHTTPServer(&mainLoop, threadNum, port);
myHTTPServer.start();
mainLoop.loop();
return 0;
}