ithewei 3 jaren geleden
bovenliggende
commit
915cc8e2b8
6 gewijzigde bestanden met toevoegingen van 13 en 7 verwijderingen
  1. 1 0
      README-CN.md
  2. 1 1
      TREE.md
  3. 1 0
      cpputil/README.md
  4. 5 5
      event/nio.c
  5. 1 1
      http/client/AsyncHttpClient.cpp
  6. 4 0
      http/client/http_client.cpp

+ 1 - 0
README-CN.md

@@ -495,6 +495,7 @@ ab -c 100 -n 100000 http://127.0.0.1:8080/
 - [libhv教程16--多线程/多进程服务端编程](https://hewei.blog.csdn.net/article/details/120366024)
 - [libhv教程17--Qt中使用libhv](https://hewei.blog.csdn.net/article/details/120699890)
 - [libhv教程18--动手写一个tinyhttpd](https://hewei.blog.csdn.net/article/details/121706604)
+- [libhv教程19--MQTT的实现与使用](https://hewei.blog.csdn.net/article/details/122753665)
 
 ## 💎 用户案例
 

+ 1 - 1
TREE.md

@@ -7,7 +7,7 @@
 ├── build       cmake默认构建目录
 ├── cert        SSL证书存放目录
 ├── cmake       cmake脚本存放目录
-├── cpputil     libhv工具类,如命令行解析、json解析、ini解析
+├── cpputil     libhv工具类,如字符串、文件、路径、线程池、json解析、ini解析
 ├── docs        文档存放目录
 ├── echo-servers 包含libevent、libev、libuv、libhv、asio、poco、muduo等多个网络库的tcp echo server写法,并做压力测试
 ├── etc         应用程序配置目录

+ 1 - 0
cpputil/README.md

@@ -6,6 +6,7 @@
 ├── hdir.h          目录(ls实现)
 ├── hfile.h         文件类
 ├── hobjectpool.h   对象池
+├── hpath.h         路径操作
 ├── hscope.h        作用域模板类
 ├── hstring.h       字符串操作
 ├── hthreadpool.h   线程池

+ 5 - 5
event/nio.c

@@ -180,8 +180,7 @@ static void nio_connect(hio_t* io) {
     int ret = getpeername(io->fd, io->peeraddr, &addrlen);
     if (ret < 0) {
         io->error = socket_errno();
-        printd("connect failed: %s: %d\n", strerror(io->error), io->error);
-        goto connect_failed;
+        goto connect_error;
     }
     else {
         addrlen = sizeof(sockaddr_u);
@@ -200,11 +199,11 @@ static void nio_connect(hio_t* io) {
                     io->alloced_ssl_ctx = 1;
                 }
                 if (ssl_ctx == NULL) {
-                    goto connect_failed;
+                    goto connect_error;
                 }
                 hssl_t ssl = hssl_new(ssl_ctx, io->fd);
                 if (ssl == NULL) {
-                    goto connect_failed;
+                    goto connect_error;
                 }
                 io->ssl = ssl;
             }
@@ -218,7 +217,8 @@ static void nio_connect(hio_t* io) {
         return;
     }
 
-connect_failed:
+connect_error:
+    hlogw("connfd=%d connect error: %s:%d\n", io->fd, socket_strerror(io->error), io->error);
     hio_close(io);
 }
 

+ 1 - 1
http/client/AsyncHttpClient.cpp

@@ -138,7 +138,7 @@ int AsyncHttpClient::sendRequest(const SocketChannelPtr& channel) {
     HttpResponse* resp = ctx->resp.get();
 
     if (ctx->parser == NULL) {
-        ctx->parser.reset(HttpParser::New(HTTP_CLIENT, (http_version)ctx->task->req->http_major));
+        ctx->parser.reset(HttpParser::New(HTTP_CLIENT, (http_version)req->http_major));
     }
     if (resp == NULL) {
         resp = new HttpResponse;

+ 4 - 0
http/client/http_client.cpp

@@ -557,6 +557,10 @@ recv:
             nrecv = recv(connfd, recvbuf, sizeof(recvbuf), 0);
         }
         if (nrecv <= 0) {
+            if (resp->content_length == 0 && resp->http_major == 1 && resp->http_minor == 0) {
+                // HTTP/1.0, assume close after body
+                goto disconnect;
+            }
             if (++fail_cnt == 1) {
                 // maybe keep-alive timeout, try again
                 cli->Close();