mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-29 18:37:41 +08:00
optimize samples
This commit is contained in:
parent
907466e99b
commit
84ab91ca36
@ -430,6 +430,8 @@ static void usage(const char* procname)
|
||||
{
|
||||
printf("usage: %s -h[help]\r\n"
|
||||
" -s server_addr\r\n"
|
||||
" -H host[default: www.baidu.com]\r\n"
|
||||
" -L url[default: /]\r\n"
|
||||
" -D [if in debug mode, default: false]\r\n"
|
||||
" -c cocorrent\r\n"
|
||||
" -t connect_timeout[default: 5]\r\n"
|
||||
@ -460,11 +462,11 @@ int main(int argc, char* argv[])
|
||||
int ch, conn_timeout = 5, rw_timeout = 5;
|
||||
std::vector<acl::string> name_servers;
|
||||
acl::string addr("127.0.0.1:80");
|
||||
acl::string host("www.baidu.com"), ssl_lib_path;
|
||||
acl::string host("www.baidu.com"), url("/"), ssl_lib_path;
|
||||
bool enable_gzip = false, keep_alive = false, debug = false;
|
||||
bool ws_enable = false, enable_unzip = false;
|
||||
|
||||
while ((ch = getopt(argc, argv, "hs:S:N:H:t:i:ZUKDW")) > 0) {
|
||||
while ((ch = getopt(argc, argv, "hs:S:N:H:L:t:i:ZUKDW")) > 0) {
|
||||
switch (ch) {
|
||||
case 'h':
|
||||
usage(argv[0]);
|
||||
@ -475,6 +477,9 @@ int main(int argc, char* argv[])
|
||||
case 'S':
|
||||
ssl_lib_path = optarg;
|
||||
break;
|
||||
case 'L':
|
||||
url = optarg;
|
||||
break;
|
||||
case 'N':
|
||||
add_dns(name_servers, optarg);
|
||||
break;
|
||||
@ -587,7 +592,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
// 设置 HTTP 请求头,也可将此过程放在 conn->on_connect() 里
|
||||
acl::http_header& head = conn->request_header();
|
||||
head.set_url("/")
|
||||
head.set_url(url)
|
||||
.set_content_length(0)
|
||||
.set_host(host)
|
||||
.accept_gzip(enable_gzip)
|
||||
|
@ -165,15 +165,28 @@ static void usage(const char* procname)
|
||||
" -U url\r\n"
|
||||
" -H host\r\n"
|
||||
" -K [http keep_alive true]\r\n"
|
||||
" -N name_server[default: 8.8.8.8:53]\r\n"
|
||||
" -N name_server_list[default: 8.8.8.8:53]\r\n"
|
||||
, procname);
|
||||
}
|
||||
|
||||
static void add_name_servers(std::vector<acl::string>& addrs, const char* s)
|
||||
{
|
||||
acl::string buf(s);
|
||||
const std::vector<acl::string>& tokens = buf.split2(",; \t");
|
||||
|
||||
for (std::vector<acl::string>::const_iterator cit = tokens.begin();
|
||||
cit != tokens.end(); ++cit) {
|
||||
|
||||
addrs.push_back(*cit);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int ch, conn_timeout = 5, rw_timeout = 5, cocurrent = 1;
|
||||
acl::string addr("pvwu8bubc.bkt.clouddn.com:80"), name_server("8.8.8.8:53");
|
||||
acl::string addr("pvwu8bubc.bkt.clouddn.com:80");
|
||||
acl::string host("pvwu8bubc.bkt.clouddn.com"), url("/20160528212429_c2HAm.jpeg");
|
||||
std::vector<acl::string> name_servers;
|
||||
bool debug = false, keep_alive = false;
|
||||
acl::string event("kernel");
|
||||
acl::aio_handle_type event_type;
|
||||
@ -196,7 +209,7 @@ int main(int argc, char* argv[])
|
||||
addr = optarg;
|
||||
break;
|
||||
case 'N':
|
||||
name_server = optarg;
|
||||
add_name_servers(name_servers, optarg);
|
||||
break;
|
||||
case 'U':
|
||||
url = optarg;
|
||||
@ -218,6 +231,10 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (name_servers.empty()) {
|
||||
name_servers.push_back("8.8.8.8:53");
|
||||
}
|
||||
|
||||
acl::acl_cpp_init();
|
||||
acl::log::stdout_open(true);
|
||||
|
||||
@ -238,10 +255,13 @@ int main(int argc, char* argv[])
|
||||
handle.set_delay_sec(0);
|
||||
handle.set_delay_usec(1000000);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 设置 DNS 域名服务器地址
|
||||
handle.set_dns(name_server.c_str(), 5);
|
||||
for (std::vector<acl::string>::const_iterator cit = name_servers.begin();
|
||||
cit != name_servers.end(); ++cit) {
|
||||
handle.set_dns(*cit, 5);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 开始异步连接远程 WEB 服务器
|
||||
for (int i = 0; i < cocurrent; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user