From e6eebd495996c1b71840e8293fc58b6a5f9cc4c7 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Mon, 22 Jul 2024 15:03:00 +0800 Subject: [PATCH 1/3] default port --- include/cinatra/coro_http_client.hpp | 21 +++++++++++---------- include/cinatra/uri.hpp | 4 ++-- lang/coro_http_client_introduction.md | 2 +- tests/test_cinatra.cpp | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/cinatra/coro_http_client.hpp b/include/cinatra/coro_http_client.hpp index 063ccb68..239e1217 100644 --- a/include/cinatra/coro_http_client.hpp +++ b/include/cinatra/coro_http_client.hpp @@ -1546,20 +1546,21 @@ class coro_http_client : public std::enable_shared_from_this { if (!proxy_host_.empty() && !proxy_port_.empty()) { if (!proxy_request_uri_.empty()) proxy_request_uri_.clear(); - if (u.get_port() == "http") { - proxy_request_uri_ += "http://" + u.get_host() + ":"; - proxy_request_uri_ += "80"; + if (u.get_port() == "80") { + proxy_request_uri_.append("http://").append(u.get_host()).append(":80"); } - else if (u.get_port() == "https") { - proxy_request_uri_ += "https://" + u.get_host() + ":"; - proxy_request_uri_ += "443"; + else if (u.get_port() == "443") { + proxy_request_uri_.append("https://") + .append(u.get_host()) + .append(":443"); } else { // all be http - proxy_request_uri_ += "http://" + u.get_host() + ":"; - proxy_request_uri_ += u.get_port(); + proxy_request_uri_.append("http://") + .append(u.get_host()) + .append(u.get_port()); } - proxy_request_uri_ += u.get_path(); + proxy_request_uri_.append(u.get_path()); u.path = std::string_view(proxy_request_uri_); } } @@ -2424,7 +2425,7 @@ class coro_http_client : public std::enable_shared_from_this { bool enable_follow_redirect_ = false; bool enable_timeout_ = false; std::chrono::steady_clock::duration conn_timeout_duration_ = - std::chrono::seconds(30); + std::chrono::seconds(8); std::chrono::steady_clock::duration req_timeout_duration_ = std::chrono::seconds(60); bool enable_tcp_no_delay_ = true; diff --git a/include/cinatra/uri.hpp b/include/cinatra/uri.hpp index 4c1aedaa..089ce4b3 100644 --- a/include/cinatra/uri.hpp +++ b/include/cinatra/uri.hpp @@ -232,7 +232,7 @@ class uri_t { std::string port_str; if (is_ssl) { if (port.empty()) { - port_str = "https"; + port_str = "443"; } else { port_str = std::string(port); @@ -240,7 +240,7 @@ class uri_t { } else { if (port.empty()) { - port_str = "http"; + port_str = "80"; } else { port_str = std::string(port); diff --git a/lang/coro_http_client_introduction.md b/lang/coro_http_client_introduction.md index 9bcdebc6..8e74f3b2 100644 --- a/lang/coro_http_client_introduction.md +++ b/lang/coro_http_client_introduction.md @@ -252,7 +252,7 @@ async_simple::coro::Lazy test_async_client() { // 通过重连复用client1 r = async_simple::coro::syncAwait(client1.connect("http://cn.bing.com")); CHECK(client1.get_host() == "cn.bing.com"); - CHECK(client1.get_port() == "http"); + CHECK(client1.get_port() == "80"); CHECK(r.status == 200); ``` diff --git a/tests/test_cinatra.cpp b/tests/test_cinatra.cpp index 08c3de7c..d066acfa 100644 --- a/tests/test_cinatra.cpp +++ b/tests/test_cinatra.cpp @@ -753,7 +753,7 @@ TEST_CASE("test coro_http_client async_http_connect") { r = async_simple::coro::syncAwait(client1.connect("http://cn.bing.com")); CHECK(client1.get_host() == "cn.bing.com"); - CHECK(client1.get_port() == "http"); + CHECK(client1.get_port() == "80"); CHECK(r.status >= 200); r = async_simple::coro::syncAwait(client1.connect("http://www.baidu.com")); From 5a96372588aec18d18b8e5ec83b4dfcb70649165 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Wed, 30 Oct 2024 15:03:21 +0800 Subject: [PATCH 2/3] sync --- .github/workflows/linux_llvm_cov.yml | 4 ++-- include/cinatra/ylt/coro_io/coro_io.hpp | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/linux_llvm_cov.yml b/.github/workflows/linux_llvm_cov.yml index 54135d57..0b74cba8 100644 --- a/.github/workflows/linux_llvm_cov.yml +++ b/.github/workflows/linux_llvm_cov.yml @@ -43,7 +43,7 @@ jobs: ./test_metric llvm-profdata merge -sparse test_cinatra-*.profraw -o test_cinatra.profdata - llvm-cov show test_cinatra -object test_corofile -object test_time_util -object test_http_parse -object test_metric -instr-profile=test_cinatra.profdata -format=html -output-dir=../.coverage_llvm_cov -ignore-filename-regex="example|asio|cmdline|async_simple|tests" -show-instantiations=false + llvm-cov show -object test_cinatra -object test_corofile -object test_time_util -object test_http_parse -object test_metric -instr-profile=test_cinatra.profdata -format=html -output-dir=../.coverage_llvm_cov -ignore-filename-regex="example|asio|cmdline|async_simple|tests" -show-instantiations=false echo "Done!" - name: Upload Coverage Results @@ -58,7 +58,7 @@ jobs: echo "Code Coverage Report" > tmp.log echo "for detail, [goto summary](https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/${{github.run_id}}) download Artifacts `llvm-cov`" >> tmp.log echo "\`\`\`" >> tmp.log - llvm-cov report test_cinatra -object test_corofile -object test_time_util -object test_http_parse -instr-profile=test_cinatra.profdata -ignore-filename-regex="example|asio|cmdline|async_simple|tests" -show-region-summary=false >> tmp.log + llvm-cov report -object test_cinatra -object test_corofile -object test_time_util -object test_http_parse -instr-profile=test_cinatra.profdata -ignore-filename-regex="example|asio|cmdline|async_simple|tests" -show-region-summary=false >> tmp.log echo "\`\`\`" >> tmp.log - name: Create Comment diff --git a/include/cinatra/ylt/coro_io/coro_io.hpp b/include/cinatra/ylt/coro_io/coro_io.hpp index f22b9144..3992116c 100644 --- a/include/cinatra/ylt/coro_io/coro_io.hpp +++ b/include/cinatra/ylt/coro_io/coro_io.hpp @@ -364,12 +364,11 @@ post(Func func, } template -struct coro_channel - : public asio::experimental::channel { +struct channel : public asio::experimental::channel { using return_type = R; using ValueType = std::pair; using asio::experimental::channel::channel; - coro_channel(coro_io::ExecutorWrapper<> *executor, size_t capacity) + channel(coro_io::ExecutorWrapper<> *executor, size_t capacity) : executor_(executor), asio::experimental::channel( executor->get_asio_executor(), capacity) {} @@ -380,17 +379,17 @@ struct coro_channel }; template -inline coro_channel create_channel( +inline channel create_channel( size_t capacity, coro_io::ExecutorWrapper<> *executor = coro_io::get_global_executor()) { - return coro_channel(executor, capacity); + return channel(executor, capacity); } template inline auto create_shared_channel( size_t capacity, coro_io::ExecutorWrapper<> *executor = coro_io::get_global_executor()) { - return std::make_shared>(executor, capacity); + return std::make_shared>(executor, capacity); } template From fa9c3afbd7157a29b25312ad431999cfc7c51d19 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Wed, 30 Oct 2024 15:53:43 +0800 Subject: [PATCH 3/3] improve metric --- include/cinatra/ylt/metric/dynamic_metric.hpp | 3 +++ include/cinatra/ylt/metric/metric.hpp | 2 -- include/cinatra/ylt/metric/system_metric.hpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/cinatra/ylt/metric/dynamic_metric.hpp b/include/cinatra/ylt/metric/dynamic_metric.hpp index 02533bbe..df024e54 100644 --- a/include/cinatra/ylt/metric/dynamic_metric.hpp +++ b/include/cinatra/ylt/metric/dynamic_metric.hpp @@ -2,6 +2,7 @@ #include #include "metric.hpp" +#include "thread_local_value.hpp" #if __has_include("ylt/util/type_traits.h") #include "ylt/util/map_sharded.hpp" #else @@ -12,6 +13,8 @@ namespace ylt::metric { class dynamic_metric : public metric_t { public: + static inline auto g_user_metric_label_count = + new thread_local_value(std::thread::hardware_concurrency()); using metric_t::metric_t; }; diff --git a/include/cinatra/ylt/metric/metric.hpp b/include/cinatra/ylt/metric/metric.hpp index cd395268..fddd50f3 100644 --- a/include/cinatra/ylt/metric/metric.hpp +++ b/include/cinatra/ylt/metric/metric.hpp @@ -53,8 +53,6 @@ struct metric_filter_options { class metric_t { public: static inline std::atomic g_user_metric_count = 0; - static inline auto g_user_metric_label_count = - new thread_local_value(std::thread::hardware_concurrency()); metric_t() = default; metric_t(MetricType type, std::string name, std::string help) : type_(type), diff --git a/include/cinatra/ylt/metric/system_metric.hpp b/include/cinatra/ylt/metric/system_metric.hpp index 50c36f31..7d286caf 100644 --- a/include/cinatra/ylt/metric/system_metric.hpp +++ b/include/cinatra/ylt/metric/system_metric.hpp @@ -601,7 +601,7 @@ inline void stat_metric() { system_metric_manager::instance().get_metric_static( "ylt_user_metric_labels"); user_metric_label_count->update( - metric::metric_t::g_user_metric_label_count->value()); + dynamic_metric::g_user_metric_label_count->value()); } inline void ylt_stat() {