hewei.it 4 years ago
parent
commit
342e410e67
3 changed files with 23 additions and 9 deletions
  1. 8 1
      README-CN.md
  2. 8 1
      README.md
  3. 7 7
      examples/wget.cpp

+ 8 - 1
README-CN.md

@@ -173,7 +173,6 @@ wrk -c 100 -t 4 -d 10s http://127.0.0.1:8080/
 - TCP代理服务:  [examples/tcp_proxy_server.c](examples/tcp_proxy_server.c)
 - UDP回显服务:  [examples/udp_echo_server.c](examples/udp_echo_server.c)
 - UDP代理服务:  [examples/udp_proxy_server.c](examples/udp_proxy_server.c)
-- TCP/UDP客户端: [examples/nc.c](examples/nc.c)
 
 ### c++版本
 - 事件循环: [evpp/EventLoop_test.cpp](evpp/EventLoop_test.cpp)
@@ -188,6 +187,14 @@ wrk -c 100 -t 4 -d 10s http://127.0.0.1:8080/
 - WebSocket服务端: [examples/websocket_server_test.cpp](examples/websocket_server_test.cpp)
 - WebSocket客户端: [examples/websocket_client_test.cpp](examples/websocket_client_test.cpp)
 
+### 模拟实现著名的命令行工具
+- 网络连接工具: [examples/nc](examples/nc.c)
+- 网络扫描工具: [examples/nmap](examples/nmap)
+- HTTP服务程序: [examples/httpd](examples/httpd)
+- URL请求工具: [examples/curl](examples/curl.cpp)
+- 文件下载工具: [examples/wget](examples/wget.cpp)
+- 服务注册与发现: [examples/consul](examples/consul)
+
 ## 🥇 性能测试
 ```shell
 cd echo-servers

+ 8 - 1
README.md

@@ -170,7 +170,6 @@ wrk -c 100 -t 4 -d 10s http://127.0.0.1:8080/
 - [examples/tcp_proxy_server.c](examples/tcp_proxy_server.c)
 - [examples/udp_echo_server.c](examples/udp_echo_server.c)
 - [examples/udp_proxy_server.c](examples/udp_proxy_server.c)
-- [examples/nc.c](examples/nc.c)
 
 ### c++ version
 - [evpp/EventLoop_test.cpp](evpp/EventLoop_test.cpp)
@@ -185,6 +184,14 @@ wrk -c 100 -t 4 -d 10s http://127.0.0.1:8080/
 - [examples/websocket_server_test.cpp](examples/websocket_server_test.cpp)
 - [examples/websocket_client_test.cpp](examples/websocket_client_test.cpp)
 
+### simulate well-known command line tools
+- [examples/nc](examples/nc.c)
+- [examples/nmap](examples/nmap)
+- [examples/httpd](examples/httpd)
+- [examples/curl](examples/curl.cpp)
+- [examples/wget](examples/wget.cpp)
+- [examples/consul](examples/consul)
+
 ## 🥇 Benchmark
 ```shell
 cd echo-servers

+ 7 - 7
examples/wget.cpp

@@ -20,7 +20,7 @@ int main(int argc, char** argv) {
     } else {
         filepath = path + 1;
     }
-    printf("save file to %s ...\n", filepath.c_str());
+    printf("Save file to %s ...\n", filepath.c_str());
 
     HFile file;
     if (file.open(filepath.c_str(), "wb") != 0) {
@@ -32,13 +32,13 @@ int main(int argc, char** argv) {
     requests::Request req(new HttpRequest);
     req->url = url;
     req->method = HTTP_HEAD;
-    printf("%s\n", req->Dump(true, true).c_str());
+    printd("%s", req->Dump(true, true).c_str());
     auto resp = requests::request(req);
     if (resp == NULL) {
         fprintf(stderr, "request failed!\n");
         return -1;
     }
-    printf("%s\n", resp->Dump(true, false).c_str());
+    printd("%s", resp->Dump(true, false).c_str());
 
     bool use_range = false;
     int range_bytes = 1 << 20; // 1M
@@ -54,13 +54,13 @@ int main(int argc, char** argv) {
     // GET
     req->method = HTTP_GET;
     if (!use_range) {
-        printf("%s\n", req->Dump(true, true).c_str());
+        printd("%s", req->Dump(true, true).c_str());
         resp = requests::get(url);
         if (resp == NULL) {
             fprintf(stderr, "request failed!\n");
             return -1;
         }
-        printf("%s\n", resp->Dump(true, false).c_str());
+        printd("%s", resp->Dump(true, false).c_str());
         file.write(resp->body.data(), resp->body.size());
         return 0;
     }
@@ -74,13 +74,13 @@ int main(int argc, char** argv) {
         if (to >= content_length) to = content_length - 1;
         // Range: bytes=from-to
         req->SetRange(from, to);
-        printf("%s\n", req->Dump(true, true).c_str());
+        printd("%s", req->Dump(true, true).c_str());
         int ret = http_client_send(cli, req.get(), resp.get());
         if (ret != 0) {
             fprintf(stderr, "request failed!\n");
             return -1;
         }
-        printf("%s\n", resp->Dump(true, false).c_str());
+        printd("%s", resp->Dump(true, false).c_str());
         file.write(resp->body.data(), resp->body.size());
         from = to + 1;
     }