forked from linyacool/WebServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
executable file
·55 lines (53 loc) · 1.3 KB
/
Copy pathMain.cpp
File metadata and controls
executable file
·55 lines (53 loc) · 1.3 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
// @Author Lin Ya
// @Email [email protected]
#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;
}
}
Logger::setLogFileName(logPath);
// STL库在多线程上应用
#ifndef _PTHREADS
LOG << "_PTHREADS is not defined !";
#endif
EventLoop mainLoop;
Server myHTTPServer(&mainLoop, threadNum, port);
myHTTPServer.start();
mainLoop.loop();
return 0;
}