From 38fcdb3cd468f050460bd0c518232bb4c664420e Mon Sep 17 00:00:00 2001 From: qicosmos Date: Wed, 1 Nov 2023 17:49:16 +0800 Subject: [PATCH] [coro_http_client][improve]some improvment (#485) --- include/ylt/coro_http/coro_http_client.hpp | 1 + include/ylt/thirdparty/cinatra/coro_http_client.hpp | 9 +++++---- src/coro_io/tests/test_client_pool.cpp | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/ylt/coro_http/coro_http_client.hpp b/include/ylt/coro_http/coro_http_client.hpp index ac33ce3c8..6573b0ece 100644 --- a/include/ylt/coro_http/coro_http_client.hpp +++ b/include/ylt/coro_http/coro_http_client.hpp @@ -32,6 +32,7 @@ using req_content_type = cinatra::req_content_type; using resp_data = cinatra::resp_data; using http_method = cinatra::http_method; using http_header = cinatra::http_header; +using uri_t = cinatra::uri_t; template using req_context = cinatra::req_context; } // namespace coro_http \ No newline at end of file diff --git a/include/ylt/thirdparty/cinatra/coro_http_client.hpp b/include/ylt/thirdparty/cinatra/coro_http_client.hpp index a82649dde..9ccff8080 100644 --- a/include/ylt/thirdparty/cinatra/coro_http_client.hpp +++ b/include/ylt/thirdparty/cinatra/coro_http_client.hpp @@ -81,12 +81,12 @@ struct http_header; struct resp_data { std::error_code net_err; - int status; + int status = 0; + bool eof = false; std::string_view resp_body; std::span resp_headers; - bool eof; #ifdef BENCHMARK_TEST - uint64_t total; + uint64_t total = 0; #endif }; @@ -104,7 +104,7 @@ struct multipart_t { size_t size = 0; }; -class coro_http_client { +class coro_http_client : public std::enable_shared_from_this { public: struct config { std::optional conn_timeout_duration; @@ -1578,6 +1578,7 @@ class coro_http_client { async_simple::coro::Lazy async_read_ws() { resp_data data{}; + auto self = this->shared_from_this(); read_buf_.consume(read_buf_.size()); size_t header_size = 2; std::shared_ptr sock = socket_; diff --git a/src/coro_io/tests/test_client_pool.cpp b/src/coro_io/tests/test_client_pool.cpp index f4cff502e..f1d9d64a0 100644 --- a/src/coro_io/tests/test_client_pool.cpp +++ b/src/coro_io/tests/test_client_pool.cpp @@ -220,10 +220,10 @@ TEST_CASE("test client pools parallel r/w") { CHECK(cli->get_host_name() == std::to_string(i)); } auto rw = [&pool](int i) -> Lazy { - ELOG_DEBUG << "start to insert {" << i << "} to hash table."; + // ELOG_DEBUG << "start to insert {" << i << "} to hash table."; auto cli = pool[std::to_string(i)]; CHECK(cli->get_host_name() == std::to_string(i)); - ELOG_DEBUG << "end to insert {" << i << "} to hash table."; + // ELOG_DEBUG << "end to insert {" << i << "} to hash table."; co_return; };