forked from qinguoyi/TinyWebServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.cpp
More file actions
113 lines (102 loc) · 2.41 KB
/
config.cpp
File metadata and controls
113 lines (102 loc) · 2.41 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "config.h"
#include <unistd.h>
#include <stdlib.h>
Config::Config(){
//端口号,默认9006
PORT = 9006;
HTTPS_PORT = 443;
USE_HTTPS = 1;
SSL_CERT_PATH = "./server.crt"; // 默认路径
SSL_KEY_PATH = "./server.key";
//日志写入方式,默认异步
LOGWrite = 1; // 0:同步,1:异步
//触发组合模式,默认listenfd LT + connfd LT
TRIGMode = 0;
//listenfd触发模式,默认LT
LISTENTrigmode = 0;
//connfd触发模式,默认LT
CONNTrigmode = 0;
//优雅关闭链接,默认不使用
OPT_LINGER = 0;
//数据库连接池数量,默认8
sql_num = 8;
//线程池内的线程数量,默认8
thread_num = 8;
//关闭日志,默认不关闭
close_log = 0;
//并发模型,默认是proactor
actor_model = 0;
// 新增:异步日志队列大小,默认1000
log_queue_size = 1000;
// HTTP连接池大小,默认100
http_conn_pool_size = 100;
// HTTP连接超时时间,默认15秒
http_conn_timeout = 15;
}
void Config::parse_arg(int argc, char*argv[]){
int opt;
const char *str = "p:l:m:o:s:t:c:a:q:h:H:";
while ((opt = getopt(argc, argv, str)) != -1)
{
switch (opt)
{
case 'p':
{
PORT = atoi(optarg);
break;
}
case 'l':
{
LOGWrite = atoi(optarg);
break;
}
case 'm':
{
TRIGMode = atoi(optarg);
break;
}
case 'o':
{
OPT_LINGER = atoi(optarg);
break;
}
case 's':
{
sql_num = atoi(optarg);
break;
}
case 't':
{
thread_num = atoi(optarg);
break;
}
case 'c':
{
close_log = atoi(optarg);
break;
}
case 'a':
{
actor_model = atoi(optarg);
break;
}
case 'q': // 新增:日志队列大小参数
{
log_queue_size = atoi(optarg);
break;
}
case 'h': // HTTP连接池大小
{
http_conn_pool_size = atoi(optarg);
break;
}
case 'H': // HTTP连接超时时间
{
http_conn_timeout = atoi(optarg);
break;
}
default:
break;
}
}
}