From 5d23db41433deec95d004591d9771e49642ed831 Mon Sep 17 00:00:00 2001 From: Petr Shumilov Date: Wed, 6 May 2026 17:45:53 +0300 Subject: [PATCH 1/3] Fix code style Signed-off-by: Petr Shumilov --- .../inter-component-session/client.h | 2 +- runtime-light/stdlib/curl/curl-context.h | 11 ++++++----- .../stdlib/curl/curl-easy-functions.h | 19 ++++++++++--------- .../stdlib/curl/curl-multi-functions.h | 5 +++-- .../{details => }/web-property.h | 0 5 files changed, 20 insertions(+), 17 deletions(-) rename runtime-light/stdlib/web-transfer-lib/{details => }/web-property.h (100%) diff --git a/runtime-light/stdlib/component/inter-component-session/client.h b/runtime-light/stdlib/component/inter-component-session/client.h index a46efac1fd..934b958ed9 100644 --- a/runtime-light/stdlib/component/inter-component-session/client.h +++ b/runtime-light/stdlib/component/inter-component-session/client.h @@ -175,7 +175,7 @@ class client final { auto& buffer_providers{ctx.get()->query2resp_buffer_provider}; auto it_buffer_provider{buffer_providers.find(qid)}; - // Response provider is not present => read response into dummy buffer, just to maintain consistency + // Response provider is not present => read response into dummy buffer, just to keep consistency if (it_buffer_provider == buffer_providers.end()) { kphp::stl::vector sink_buffer{size}; std::span sink_resp{sink_buffer.data(), sink_buffer.size()}; diff --git a/runtime-light/stdlib/curl/curl-context.h b/runtime-light/stdlib/curl/curl-context.h index 513df8ce57..1761defbc2 100644 --- a/runtime-light/stdlib/curl/curl-context.h +++ b/runtime-light/stdlib/curl/curl-context.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "common/mixin/movable_only.h" #include "runtime-common/core/runtime-core.h" @@ -25,7 +26,7 @@ struct curl_context : vk::movable_only { if (code == kphp::web::WEB_INTERNAL_ERROR_CODE) [[unlikely]] { return; } - error_code = static_cast(code); + error_code = code; std::memcpy(error_description.data(), description.data(), std::min(description.size(), static_cast(CURL_ERROR_SIZE))); } @@ -38,19 +39,19 @@ struct curl_context : vk::movable_only { } inline auto set_errno(kphp::web::curl::CURLE code, std::string_view description) noexcept { - set_errno(static_cast(code), description); + set_errno(std::to_underlying(code), description); } inline auto set_errno(kphp::web::curl::CURLE code, std::optional description = std::nullopt) noexcept { - set_errno(static_cast(code), std::move(description)); + set_errno(std::to_underlying(code), std::move(description)); } inline auto set_errno(kphp::web::curl::CURLME code, std::string_view description) noexcept { - set_errno(static_cast(code), description); + set_errno(std::to_underlying(code), description); } inline auto set_errno(kphp::web::curl::CURLME code, std::optional description = std::nullopt) noexcept { - set_errno(static_cast(code), std::move(description)); + set_errno(std::to_underlying(code), std::move(description)); } template diff --git a/runtime-light/stdlib/curl/curl-easy-functions.h b/runtime-light/stdlib/curl/curl-easy-functions.h index 8724003d27..7cd0fd8cd7 100644 --- a/runtime-light/stdlib/curl/curl-easy-functions.h +++ b/runtime-light/stdlib/curl/curl-easy-functions.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "runtime-common/core/runtime-core.h" #include "runtime-light/stdlib/curl/curl-context.h" @@ -17,7 +18,7 @@ #include "runtime-light/stdlib/diagnostics/logs.h" #include "runtime-light/stdlib/fork/fork-functions.h" #include "runtime-light/stdlib/output/print-functions.h" -#include "runtime-light/stdlib/web-transfer-lib/details/web-property.h" +#include "runtime-light/stdlib/web-transfer-lib/web-property.h" #include "runtime-light/stdlib/web-transfer-lib/web-simple-transfer.h" inline auto f$curl_init(string url = string{""}) noexcept -> kphp::coro::task { @@ -46,7 +47,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co auto& easy_ctx{curl_state.easy_ctx.get_or_init(easy_id)}; auto st{kphp::web::simple_transfer{.descriptor = easy_id}}; - if (option == static_cast(kphp::web::curl::CURLINFO::HEADER_OUT)) { + if (option == std::to_underlying(kphp::web::curl::CURLINFO::HEADER_OUT)) { auto res{kphp::web::set_transfer_property(st, static_cast(kphp::web::curl::CURLOPT::VERBOSE), kphp::web::property_value::as_long(value.to_int()))}; if (!res.has_value()) [[unlikely]] { @@ -56,7 +57,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co return true; } - if (option == static_cast(kphp::web::curl::PHPCURL::RETURNTRANSFER)) { + if (option == std::to_underlying(kphp::web::curl::PHPCURL::RETURNTRANSFER)) { easy_ctx.return_transfer = (value.to_int()); easy_ctx.set_errno(kphp::web::curl::CURLE::OK); return true; @@ -272,7 +273,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURLPROXY::SOCKS5: case kphp::web::curl::CURLPROXY::SOCKS4A: case kphp::web::curl::CURLPROXY::SOCKS5_HOSTNAME: { - auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(static_cast(proxy_type)))}; + auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(std::to_underlying(proxy_type)))}; if (!res.has_value()) [[unlikely]] { kphp::web::curl::print_error("could not set an option", std::move(res.error())); return false; @@ -299,7 +300,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURL_SSLVERSION::TLSv1_1: case kphp::web::curl::CURL_SSLVERSION::TLSv1_2: case kphp::web::curl::CURL_SSLVERSION::TLSv1_3: { - auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(static_cast(ssl_version)))}; + auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(std::to_underlying(ssl_version)))}; if (!res.has_value()) [[unlikely]] { kphp::web::curl::print_error("could not set an option", std::move(res.error())); return false; @@ -318,7 +319,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURL_IPRESOLVE::WHATEVER: case kphp::web::curl::CURL_IPRESOLVE::V4: case kphp::web::curl::CURL_IPRESOLVE::V6: { - auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(static_cast(ip_resolve)))}; + auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(std::to_underlying(ip_resolve)))}; if (!res.has_value()) [[unlikely]] { kphp::web::curl::print_error("could not set an option", std::move(res.error())); return false; @@ -337,7 +338,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURL_NETRC::IGNORED: case kphp::web::curl::CURL_NETRC::OPTIONAL: case kphp::web::curl::CURL_NETRC::REQUIRED: { - auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(static_cast(netrc)))}; + auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(std::to_underlying(netrc)))}; if (!res.has_value()) [[unlikely]] { kphp::web::curl::print_error("could not set an option", std::move(res.error())); return false; @@ -359,7 +360,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURL_HTTP_VERSION::_2_0: case kphp::web::curl::CURL_HTTP_VERSION::_2TLS: case kphp::web::curl::CURL_HTTP_VERSION::_2_PRIOR_KNOWLEDGE: { - auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(static_cast(http_version)))}; + auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(std::to_underlying(http_version)))}; if (!res.has_value()) [[unlikely]] { kphp::web::curl::print_error("could not set an option", std::move(res.error())); return false; @@ -495,7 +496,7 @@ inline auto f$curl_error(kphp::web::curl::easy_type easy_id) noexcept -> string return {}; } auto& easy_ctx{curl_state.easy_ctx.get_or_init(easy_id)}; - if (easy_ctx.error_code != static_cast(kphp::web::curl::CURLE::OK)) [[likely]] { + if (easy_ctx.error_code != std::to_underlying((kphp::web::curl::CURLE::OK))) [[likely]] { const auto* const desc_data{reinterpret_cast(easy_ctx.error_description.data())}; const auto desc_size{static_cast(easy_ctx.error_description.size())}; return string{desc_data, desc_size}; diff --git a/runtime-light/stdlib/curl/curl-multi-functions.h b/runtime-light/stdlib/curl/curl-multi-functions.h index c14552a36e..18e2c13071 100644 --- a/runtime-light/stdlib/curl/curl-multi-functions.h +++ b/runtime-light/stdlib/curl/curl-multi-functions.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "runtime-common/core/runtime-core.h" #include "runtime-light/coroutine/task.h" @@ -17,8 +18,8 @@ #include "runtime-light/stdlib/curl/details/diagnostics.h" #include "runtime-light/stdlib/fork/fork-functions.h" #include "runtime-light/stdlib/web-transfer-lib/defs.h" -#include "runtime-light/stdlib/web-transfer-lib/details/web-property.h" #include "runtime-light/stdlib/web-transfer-lib/web-composite-transfer.h" +#include "runtime-light/stdlib/web-transfer-lib/web-property.h" #include "runtime-light/stdlib/web-transfer-lib/web-simple-transfer.h" inline auto f$curl_multi_init() noexcept -> kphp::coro::task { @@ -91,7 +92,7 @@ inline auto f$curl_multi_setopt(kphp::web::curl::multi_type multi_id, int64_t op case kphp::web::curl::CURLPIPE::NOTHING: case kphp::web::curl::CURLPIPE::HTTP1: case kphp::web::curl::CURLPIPE::MULTIPLEX: { - auto res{kphp::web::set_transfer_property(ct, option, kphp::web::property_value::as_long(static_cast(pipeling_type)))}; + auto res{kphp::web::set_transfer_property(ct, option, kphp::web::property_value::as_long(std::to_underlying(pipeling_type)))}; if (!res.has_value()) [[unlikely]] { kphp::web::curl::print_error("could not set an mutli option", std::move(res.error())); return false; diff --git a/runtime-light/stdlib/web-transfer-lib/details/web-property.h b/runtime-light/stdlib/web-transfer-lib/web-property.h similarity index 100% rename from runtime-light/stdlib/web-transfer-lib/details/web-property.h rename to runtime-light/stdlib/web-transfer-lib/web-property.h From 21b0aa6032ea8a7281be227af54220c75c20d60b Mon Sep 17 00:00:00 2001 From: Petr Shumilov Date: Wed, 6 May 2026 19:04:26 +0300 Subject: [PATCH 2/3] Move literals into image state Signed-off-by: Petr Shumilov --- .../stdlib/curl/curl-easy-functions.h | 49 +++++------ .../stdlib/curl/curl-multi-functions.h | 7 +- runtime-light/stdlib/curl/curl-state.h | 81 +++++++++++++++++++ runtime-light/stdlib/curl/defs.h | 26 ++++++ 4 files changed, 136 insertions(+), 27 deletions(-) diff --git a/runtime-light/stdlib/curl/curl-easy-functions.h b/runtime-light/stdlib/curl/curl-easy-functions.h index 7cd0fd8cd7..47bce53d9d 100644 --- a/runtime-light/stdlib/curl/curl-easy-functions.h +++ b/runtime-light/stdlib/curl/curl-easy-functions.h @@ -540,6 +540,7 @@ inline auto f$curl_getinfo(kphp::web::curl::easy_type easy_id, int64_t option = } }}; + const auto& image_state{CurlImageState::get()}; if (!easy_ctx.has_been_executed) { const auto url_opt_id{static_cast(kphp::web::curl::CURLOPT::URL)}; const auto url{co_await kphp::forks::id_managed( @@ -547,34 +548,34 @@ inline auto f$curl_getinfo(kphp::web::curl::easy_type easy_id, int64_t option = if (url.has_value()) { const auto& v{(*url).find(url_opt_id)}; kphp::log::assertion(v != (*url).end()); - result.set_value(string{"url"}, v->second.to_mixed()); + result.set_value(image_state.EASYINFO_URL, v->second.to_mixed()); } else { - result.set_value(string{"url"}, string{}); + result.set_value(image_state.EASYINFO_URL, string{}); } } else { - set_value(string{"url"}, kphp::web::curl::CURLINFO::EFFECTIVE_URL); + set_value(image_state.EASYINFO_URL, kphp::web::curl::CURLINFO::EFFECTIVE_URL); } - set_value(string{"content_type"}, kphp::web::curl::CURLINFO::CONTENT_TYPE); - set_value(string{"http_code"}, kphp::web::curl::CURLINFO::RESPONSE_CODE); - set_value(string{"header_size"}, kphp::web::curl::CURLINFO::HEADER_SIZE); - set_value(string{"request_size"}, kphp::web::curl::CURLINFO::REQUEST_SIZE); - set_value(string{"filetime"}, kphp::web::curl::CURLINFO::FILETIME); - set_value(string{"redirect_count"}, kphp::web::curl::CURLINFO::REDIRECT_COUNT); - set_value(string{"total_time"}, kphp::web::curl::CURLINFO::TOTAL_TIME); - set_value(string{"namelookup_time"}, kphp::web::curl::CURLINFO::NAMELOOKUP_TIME); - set_value(string{"connect_time"}, kphp::web::curl::CURLINFO::CONNECT_TIME); - set_value(string{"pretransfer_time"}, kphp::web::curl::CURLINFO::PRETRANSFER_TIME); - set_value(string{"size_upload"}, kphp::web::curl::CURLINFO::SIZE_UPLOAD); - set_value(string{"size_download"}, kphp::web::curl::CURLINFO::SIZE_DOWNLOAD); - set_value(string{"download_content_length"}, kphp::web::curl::CURLINFO::CONTENT_LENGTH_DOWNLOAD); - set_value(string{"starttransfer_time"}, kphp::web::curl::CURLINFO::STARTTRANSFER_TIME); - set_value(string{"redirect_time"}, kphp::web::curl::CURLINFO::REDIRECT_TIME); - set_value(string{"redirect_url"}, kphp::web::curl::CURLINFO::REDIRECT_URL); - set_value(string{"primary_ip"}, kphp::web::curl::CURLINFO::PRIMARY_IP); - set_value(string{"primary_port"}, kphp::web::curl::CURLINFO::PRIMARY_PORT); - set_value(string{"local_ip"}, kphp::web::curl::CURLINFO::LOCAL_IP); - set_value(string{"local_port"}, kphp::web::curl::CURLINFO::LOCAL_PORT); - set_value(string{"request_header"}, kphp::web::curl::CURLINFO::HEADER_OUT); + set_value(image_state.EASYINFO_CONTENT_TYPE, kphp::web::curl::CURLINFO::CONTENT_TYPE); + set_value(image_state.EASYINFO_HTTP_CODE, kphp::web::curl::CURLINFO::RESPONSE_CODE); + set_value(image_state.EASYINFO_HEADER_SIZE, kphp::web::curl::CURLINFO::HEADER_SIZE); + set_value(image_state.EASYINFO_REQUEST_SIZE, kphp::web::curl::CURLINFO::REQUEST_SIZE); + set_value(image_state.EASYINFO_FILETIME, kphp::web::curl::CURLINFO::FILETIME); + set_value(image_state.EASYINFO_REDIRECT_COUNT, kphp::web::curl::CURLINFO::REDIRECT_COUNT); + set_value(image_state.EASYINFO_TOTAL_TIME, kphp::web::curl::CURLINFO::TOTAL_TIME); + set_value(image_state.EASYINFO_NAMELOOKUP_TIME, kphp::web::curl::CURLINFO::NAMELOOKUP_TIME); + set_value(image_state.EASYINFO_CONNECT_TIME, kphp::web::curl::CURLINFO::CONNECT_TIME); + set_value(image_state.EASYINFO_PRETRANSFER_TIME, kphp::web::curl::CURLINFO::PRETRANSFER_TIME); + set_value(image_state.EASYINFO_SIZE_UPLOAD, kphp::web::curl::CURLINFO::SIZE_UPLOAD); + set_value(image_state.EASYINFO_SIZE_DOWNLOAD, kphp::web::curl::CURLINFO::SIZE_DOWNLOAD); + set_value(image_state.EASYINFO_DOWNLOAD_CONTENT_LENGTH, kphp::web::curl::CURLINFO::CONTENT_LENGTH_DOWNLOAD); + set_value(image_state.EASYINFO_STARTTRANSFER_TIME, kphp::web::curl::CURLINFO::STARTTRANSFER_TIME); + set_value(image_state.EASYINFO_REDIRECT_TIME, kphp::web::curl::CURLINFO::REDIRECT_TIME); + set_value(image_state.EASYINFO_REDIRECT_URL, kphp::web::curl::CURLINFO::REDIRECT_URL); + set_value(image_state.EASYINFO_PRIMARY_IP, kphp::web::curl::CURLINFO::PRIMARY_IP); + set_value(image_state.EASYINFO_PRIMARY_PORT, kphp::web::curl::CURLINFO::PRIMARY_PORT); + set_value(image_state.EASYINFO_LOCAL_IP, kphp::web::curl::CURLINFO::LOCAL_IP); + set_value(image_state.EASYINFO_LOCAL_PORT, kphp::web::curl::CURLINFO::LOCAL_PORT); + set_value(image_state.EASYINFO_REQUEST_HEADER, kphp::web::curl::CURLINFO::HEADER_OUT); co_return result; } case kphp::web::curl::CURLINFO::PRIVATE: { diff --git a/runtime-light/stdlib/curl/curl-multi-functions.h b/runtime-light/stdlib/curl/curl-multi-functions.h index 18e2c13071..fbfb96a394 100644 --- a/runtime-light/stdlib/curl/curl-multi-functions.h +++ b/runtime-light/stdlib/curl/curl-multi-functions.h @@ -291,18 +291,19 @@ inline auto f$curl_multi_info_read(kphp::web::curl::multi_type multi_id, (*msgs_in_queue).get() = info.get_value(MSGS_IN_QUEUE); } + const auto& image_state{CurlImageState::get()}; if (info.has_key(MSG_IDX)) { - result.set_value(string{"msg"}, info.get_value(MSG_IDX)); + result.set_value(image_state.MULTIINFO_MSG, info.get_value(MSG_IDX)); } if (info.has_key(RESULT_IDX)) { - result.set_value(string{"result"}, info.get_value(RESULT_IDX)); + result.set_value(image_state.MULTIINFO_RESULT, info.get_value(RESULT_IDX)); } if (info.has_key(HANDLE_IDX)) { auto easy_id{info.get_value(HANDLE_IDX)}; if (curl_state.easy_ctx.has(easy_id)) { - result.set_value(string{"handle"}, info.get_value(HANDLE_IDX)); + result.set_value(image_state.MULTIINFO_HANDLE, info.get_value(HANDLE_IDX)); } } diff --git a/runtime-light/stdlib/curl/curl-state.h b/runtime-light/stdlib/curl/curl-state.h index b6a551f7e2..fb260966ba 100644 --- a/runtime-light/stdlib/curl/curl-state.h +++ b/runtime-light/stdlib/curl/curl-state.h @@ -78,6 +78,35 @@ struct CurlImageState final : private vk::not_copyable { string CURLME_ABORTED_BY_CALLBACK{kphp::web::curl::details::CURLME_ABORTED_BY_CALLBACK.data(), kphp::web::curl::details::CURLME_ABORTED_BY_CALLBACK.size()}; string CURLME_UNRECOVERABLE_POLL{kphp::web::curl::details::CURLME_UNRECOVERABLE_POLL.data(), kphp::web::curl::details::CURLME_UNRECOVERABLE_POLL.size()}; + string EASYINFO_URL{kphp::web::curl::details::EASYINFO_URL.data(), kphp::web::curl::details::EASYINFO_URL.size()}; + string EASYINFO_CONTENT_TYPE{kphp::web::curl::details::EASYINFO_CONTENT_TYPE.data(), kphp::web::curl::details::EASYINFO_CONTENT_TYPE.size()}; + string EASYINFO_HTTP_CODE{kphp::web::curl::details::EASYINFO_HTTP_CODE.data(), kphp::web::curl::details::EASYINFO_HTTP_CODE.size()}; + string EASYINFO_HEADER_SIZE{kphp::web::curl::details::EASYINFO_HEADER_SIZE.data(), kphp::web::curl::details::EASYINFO_HEADER_SIZE.size()}; + string EASYINFO_REQUEST_SIZE{kphp::web::curl::details::EASYINFO_REQUEST_SIZE.data(), kphp::web::curl::details::EASYINFO_REQUEST_SIZE.size()}; + string EASYINFO_FILETIME{kphp::web::curl::details::EASYINFO_FILETIME.data(), kphp::web::curl::details::EASYINFO_FILETIME.size()}; + string EASYINFO_REDIRECT_COUNT{kphp::web::curl::details::EASYINFO_REDIRECT_COUNT.data(), kphp::web::curl::details::EASYINFO_REDIRECT_COUNT.size()}; + string EASYINFO_TOTAL_TIME{kphp::web::curl::details::EASYINFO_TOTAL_TIME.data(), kphp::web::curl::details::EASYINFO_TOTAL_TIME.size()}; + string EASYINFO_NAMELOOKUP_TIME{kphp::web::curl::details::EASYINFO_NAMELOOKUP_TIME.data(), kphp::web::curl::details::EASYINFO_NAMELOOKUP_TIME.size()}; + string EASYINFO_CONNECT_TIME{kphp::web::curl::details::EASYINFO_CONNECT_TIME.data(), kphp::web::curl::details::EASYINFO_CONNECT_TIME.size()}; + string EASYINFO_PRETRANSFER_TIME{kphp::web::curl::details::EASYINFO_PRETRANSFER_TIME.data(), kphp::web::curl::details::EASYINFO_PRETRANSFER_TIME.size()}; + string EASYINFO_SIZE_UPLOAD{kphp::web::curl::details::EASYINFO_SIZE_UPLOAD.data(), kphp::web::curl::details::EASYINFO_SIZE_UPLOAD.size()}; + string EASYINFO_SIZE_DOWNLOAD{kphp::web::curl::details::EASYINFO_SIZE_DOWNLOAD.data(), kphp::web::curl::details::EASYINFO_SIZE_DOWNLOAD.size()}; + string EASYINFO_DOWNLOAD_CONTENT_LENGTH{kphp::web::curl::details::EASYINFO_DOWNLOAD_CONTENT_LENGTH.data(), + kphp::web::curl::details::EASYINFO_DOWNLOAD_CONTENT_LENGTH.size()}; + string EASYINFO_STARTTRANSFER_TIME{kphp::web::curl::details::EASYINFO_STARTTRANSFER_TIME.data(), + kphp::web::curl::details::EASYINFO_STARTTRANSFER_TIME.size()}; + string EASYINFO_REDIRECT_TIME{kphp::web::curl::details::EASYINFO_REDIRECT_TIME.data(), kphp::web::curl::details::EASYINFO_REDIRECT_TIME.size()}; + string EASYINFO_REDIRECT_URL{kphp::web::curl::details::EASYINFO_REDIRECT_URL.data(), kphp::web::curl::details::EASYINFO_REDIRECT_URL.size()}; + string EASYINFO_PRIMARY_IP{kphp::web::curl::details::EASYINFO_PRIMARY_IP.data(), kphp::web::curl::details::EASYINFO_PRIMARY_IP.size()}; + string EASYINFO_PRIMARY_PORT{kphp::web::curl::details::EASYINFO_PRIMARY_PORT.data(), kphp::web::curl::details::EASYINFO_PRIMARY_PORT.size()}; + string EASYINFO_LOCAL_IP{kphp::web::curl::details::EASYINFO_LOCAL_IP.data(), kphp::web::curl::details::EASYINFO_LOCAL_IP.size()}; + string EASYINFO_LOCAL_PORT{kphp::web::curl::details::EASYINFO_LOCAL_PORT.data(), kphp::web::curl::details::EASYINFO_LOCAL_PORT.size()}; + string EASYINFO_REQUEST_HEADER{kphp::web::curl::details::EASYINFO_REQUEST_HEADER.data(), kphp::web::curl::details::EASYINFO_REQUEST_HEADER.size()}; + + string MULTIINFO_MSG{kphp::web::curl::details::MULTIINFO_MSG.data(), kphp::web::curl::details::MULTIINFO_MSG.size()}; + string MULTIINFO_RESULT{kphp::web::curl::details::MULTIINFO_RESULT.data(), kphp::web::curl::details::MULTIINFO_RESULT.size()}; + string MULTIINFO_HANDLE{kphp::web::curl::details::MULTIINFO_HANDLE.data(), kphp::web::curl::details::MULTIINFO_HANDLE.size()}; + CurlImageState() noexcept { kphp::log::assertion((kphp::core::set_reference_counter_recursive(CURLME_CALL_MULTI_PERFORM, ExtraRefCnt::for_global_const), kphp::core::is_reference_counter_recursive(CURLME_CALL_MULTI_PERFORM, ExtraRefCnt::for_global_const))); @@ -107,6 +136,58 @@ struct CurlImageState final : private vk::not_copyable { kphp::core::is_reference_counter_recursive(CURLME_ABORTED_BY_CALLBACK, ExtraRefCnt::for_global_const))); kphp::log::assertion((kphp::core::set_reference_counter_recursive(CURLME_UNRECOVERABLE_POLL, ExtraRefCnt::for_global_const), kphp::core::is_reference_counter_recursive(CURLME_UNRECOVERABLE_POLL, ExtraRefCnt::for_global_const))); + + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_URL, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_URL, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_CONTENT_TYPE, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_CONTENT_TYPE, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_HTTP_CODE, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_HTTP_CODE, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_HEADER_SIZE, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_HEADER_SIZE, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_REQUEST_SIZE, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_REQUEST_SIZE, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_FILETIME, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_FILETIME, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_REDIRECT_COUNT, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_REDIRECT_COUNT, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_TOTAL_TIME, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_TOTAL_TIME, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_NAMELOOKUP_TIME, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_NAMELOOKUP_TIME, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_CONNECT_TIME, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_CONNECT_TIME, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_PRETRANSFER_TIME, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_PRETRANSFER_TIME, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_SIZE_UPLOAD, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_SIZE_UPLOAD, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_SIZE_DOWNLOAD, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_SIZE_DOWNLOAD, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_DOWNLOAD_CONTENT_LENGTH, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_DOWNLOAD_CONTENT_LENGTH, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_STARTTRANSFER_TIME, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_STARTTRANSFER_TIME, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_REDIRECT_TIME, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_REDIRECT_TIME, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_REDIRECT_URL, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_REDIRECT_URL, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_PRIMARY_IP, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_PRIMARY_IP, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_PRIMARY_PORT, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_PRIMARY_PORT, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_LOCAL_IP, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_LOCAL_IP, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_LOCAL_PORT, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_LOCAL_PORT, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(EASYINFO_REQUEST_HEADER, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(EASYINFO_REQUEST_HEADER, ExtraRefCnt::for_global_const))); + + kphp::log::assertion((kphp::core::set_reference_counter_recursive(MULTIINFO_MSG, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(MULTIINFO_MSG, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(MULTIINFO_RESULT, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(MULTIINFO_RESULT, ExtraRefCnt::for_global_const))); + kphp::log::assertion((kphp::core::set_reference_counter_recursive(MULTIINFO_HANDLE, ExtraRefCnt::for_global_const), + kphp::core::is_reference_counter_recursive(MULTIINFO_HANDLE, ExtraRefCnt::for_global_const))); } static const CurlImageState& get() noexcept; diff --git a/runtime-light/stdlib/curl/defs.h b/runtime-light/stdlib/curl/defs.h index f76e433bd2..23c38ec22d 100644 --- a/runtime-light/stdlib/curl/defs.h +++ b/runtime-light/stdlib/curl/defs.h @@ -302,4 +302,30 @@ inline constexpr std::string_view CURLME_BAD_FUNCTION_ARGUMENT{"A libcurl functi inline constexpr std::string_view CURLME_ABORTED_BY_CALLBACK{"Operation was aborted by an application callback"}; inline constexpr std::string_view CURLME_UNRECOVERABLE_POLL{"Unrecoverable error in select/poll"}; +inline constexpr std::string_view EASYINFO_URL{"url"}; +inline constexpr std::string_view EASYINFO_CONTENT_TYPE{"content_type"}; +inline constexpr std::string_view EASYINFO_HTTP_CODE{"http_code"}; +inline constexpr std::string_view EASYINFO_HEADER_SIZE{"header_size"}; +inline constexpr std::string_view EASYINFO_REQUEST_SIZE{"request_size"}; +inline constexpr std::string_view EASYINFO_FILETIME{"filetime"}; +inline constexpr std::string_view EASYINFO_REDIRECT_COUNT{"redirect_count"}; +inline constexpr std::string_view EASYINFO_TOTAL_TIME{"total_time"}; +inline constexpr std::string_view EASYINFO_NAMELOOKUP_TIME{"namelookup_time"}; +inline constexpr std::string_view EASYINFO_CONNECT_TIME{"connect_time"}; +inline constexpr std::string_view EASYINFO_PRETRANSFER_TIME{"pretransfer_time"}; +inline constexpr std::string_view EASYINFO_SIZE_UPLOAD{"size_upload"}; +inline constexpr std::string_view EASYINFO_SIZE_DOWNLOAD{"size_download"}; +inline constexpr std::string_view EASYINFO_DOWNLOAD_CONTENT_LENGTH{"download_content_length"}; +inline constexpr std::string_view EASYINFO_STARTTRANSFER_TIME{"starttransfer_time"}; +inline constexpr std::string_view EASYINFO_REDIRECT_TIME{"redirect_time"}; +inline constexpr std::string_view EASYINFO_REDIRECT_URL{"redirect_url"}; +inline constexpr std::string_view EASYINFO_PRIMARY_IP{"primary_ip"}; +inline constexpr std::string_view EASYINFO_PRIMARY_PORT{"primary_port"}; +inline constexpr std::string_view EASYINFO_LOCAL_IP{"local_ip"}; +inline constexpr std::string_view EASYINFO_LOCAL_PORT{"local_port"}; +inline constexpr std::string_view EASYINFO_REQUEST_HEADER{"request_header"}; + +inline constexpr std::string_view MULTIINFO_MSG{"msg"}; +inline constexpr std::string_view MULTIINFO_RESULT{"result"}; +inline constexpr std::string_view MULTIINFO_HANDLE{"handle"}; } // namespace kphp::web::curl::details From 466ecd36c5d7a6eb7bea7eca57bfb6f7e96afa4a Mon Sep 17 00:00:00 2001 From: Petr Shumilov Date: Wed, 6 May 2026 19:21:51 +0300 Subject: [PATCH 3/3] Remove redundant curl diagnostics Signed-off-by: Petr Shumilov --- runtime-light/stdlib/curl/curl-context.h | 6 +-- .../stdlib/curl/curl-easy-functions.h | 44 +++++++++---------- .../stdlib/curl/curl-multi-functions.h | 22 +++++----- runtime-light/stdlib/curl/defs.h | 2 +- .../stdlib/curl/details/diagnostics.h | 14 +++++- 5 files changed, 49 insertions(+), 39 deletions(-) diff --git a/runtime-light/stdlib/curl/curl-context.h b/runtime-light/stdlib/curl/curl-context.h index 1761defbc2..54f28fdfb3 100644 --- a/runtime-light/stdlib/curl/curl-context.h +++ b/runtime-light/stdlib/curl/curl-context.h @@ -19,7 +19,7 @@ namespace kphp::web::curl { struct curl_context : vk::movable_only { int64_t error_code{0}; - std::array error_description{std::byte{0}}; + std::array error_description{std::byte{0}}; inline auto set_errno(int64_t code, std::string_view description) noexcept { // If Web Transfer Lib specific error @@ -27,7 +27,7 @@ struct curl_context : vk::movable_only { return; } error_code = code; - std::memcpy(error_description.data(), description.data(), std::min(description.size(), static_cast(CURL_ERROR_SIZE))); + std::memcpy(error_description.data(), description.data(), std::min(description.size(), static_cast(CURL_DIAGNOSTICS_MSG_SIZE))); } inline auto set_errno(int64_t code, std::optional description = std::nullopt) noexcept { @@ -56,7 +56,7 @@ struct curl_context : vk::movable_only { template inline auto bad_option_error(const char (&msg)[N]) noexcept { - static_assert(N <= CURL_ERROR_SIZE, "too long error"); + static_assert(N <= CURL_DIAGNOSTICS_MSG_SIZE, "too long error"); kphp::log::warning("{}", msg); set_errno(CURLE::BAD_FUNCTION_ARGUMENT, {{msg, N}}); } diff --git a/runtime-light/stdlib/curl/curl-easy-functions.h b/runtime-light/stdlib/curl/curl-easy-functions.h index 47bce53d9d..791e1c1f46 100644 --- a/runtime-light/stdlib/curl/curl-easy-functions.h +++ b/runtime-light/stdlib/curl/curl-easy-functions.h @@ -24,7 +24,7 @@ inline auto f$curl_init(string url = string{""}) noexcept -> kphp::coro::task { auto open_res{co_await kphp::forks::id_managed(kphp::web::simple_transfer_open(kphp::web::transfer_backend::CURL))}; if (!open_res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not initialize a new curl easy handle", std::move(open_res.error())); + kphp::web::curl::print_warning("could not initialize a new curl easy handle", std::move(open_res.error())); co_return 0; } const auto st{kphp::web::simple_transfer{*open_res}}; @@ -33,7 +33,7 @@ inline auto f$curl_init(string url = string{""}) noexcept -> kphp::coro::task(kphp::web::curl::CURLOPT::URL), kphp::web::property_value::as_string(url))}; if (!setopt_res.has_value()) [[unlikely]] { easy_ctx.set_errno(setopt_res.error().code, setopt_res.error().description); - kphp::web::curl::print_error("could not set URL for a new curl easy handle", std::move(setopt_res.error())); + kphp::web::curl::print_warning("could not set URL for a new curl easy handle", std::move(setopt_res.error())); co_return 0; } co_return st.descriptor; @@ -51,7 +51,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co auto res{kphp::web::set_transfer_property(st, static_cast(kphp::web::curl::CURLOPT::VERBOSE), kphp::web::property_value::as_long(value.to_int()))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an option", std::move(res.error())); } easy_ctx.set_errno(kphp::web::curl::CURLE::OK); return true; @@ -127,7 +127,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURLOPT::TCP_KEEPINTVL: { auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(value.to_int()))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an option", std::move(res.error())); return false; } easy_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -138,7 +138,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURLOPT::MAX_SEND_SPEED_LARGE: { auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(value.to_int()))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an option", std::move(res.error())); return false; } easy_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -192,7 +192,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURLOPT::ACCEPT_ENCODING: { auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_string(value.to_string()))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an option", std::move(res.error())); return false; } easy_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -222,7 +222,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co } auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_array_of_string(arr_of_str))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an option", std::move(res.error())); return false; } easy_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -233,7 +233,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co auto res{kphp::web::set_transfer_property(st, static_cast(kphp::web::curl::CURLOPT::COPYPOSTFIELDS), kphp::web::property_value::as_string(value.to_string()))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an option", std::move(res.error())); return false; } easy_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -257,7 +257,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co auto res{kphp::web::set_transfer_property(st, static_cast(kphp::web::curl::CURLOPT::HTTPPOST), kphp::web::property_value::as_array_of_string(arr_of_str))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an option", std::move(res.error())); return false; } easy_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -275,7 +275,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURLPROXY::SOCKS5_HOSTNAME: { auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(std::to_underlying(proxy_type)))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an option", std::move(res.error())); return false; } easy_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -302,7 +302,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURL_SSLVERSION::TLSv1_3: { auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(std::to_underlying(ssl_version)))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an option", std::move(res.error())); return false; } easy_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -321,7 +321,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURL_IPRESOLVE::V6: { auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(std::to_underlying(ip_resolve)))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an option", std::move(res.error())); return false; } easy_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -340,7 +340,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURL_NETRC::REQUIRED: { auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(std::to_underlying(netrc)))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an option", std::move(res.error())); return false; } easy_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -362,7 +362,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURL_HTTP_VERSION::_2_PRIOR_KNOWLEDGE: { auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(std::to_underlying(http_version)))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an option", std::move(res.error())); return false; } easy_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -378,7 +378,7 @@ inline auto f$curl_setopt(kphp::web::curl::easy_type easy_id, int64_t option, co case kphp::web::curl::CURLOPT::PROXYAUTH: { auto res{kphp::web::set_transfer_property(st, option, kphp::web::property_value::as_long(value.to_int()))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an option", std::move(res.error())); return false; } easy_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -414,7 +414,7 @@ inline auto f$curl_exec(kphp::web::curl::easy_type easy_id) noexcept -> kphp::co easy_ctx.has_been_executed = true; if (!res.has_value()) [[unlikely]] { easy_ctx.set_errno(res.error().code, res.error().description); - kphp::web::curl::print_error("could not execute curl easy handle", std::move(res.error())); + kphp::web::curl::print_debug("could not execute curl easy handle", std::move(res.error())); co_return false; } if (easy_ctx.return_transfer) { @@ -433,7 +433,7 @@ inline auto f$curl_close(kphp::web::curl::easy_type easy_id) noexcept -> kphp::c auto res{co_await kphp::forks::id_managed(kphp::web::simple_transfer_close(kphp::web::simple_transfer{easy_id}))}; if (!res.has_value()) [[unlikely]] { easy_ctx.set_errno(res.error().code, res.error().description); - kphp::web::curl::print_error("could not close curl easy handle", std::move(res.error())); + kphp::web::curl::print_warning("could not close curl easy handle", std::move(res.error())); } } @@ -446,7 +446,7 @@ inline auto f$curl_reset(kphp::web::curl::easy_type easy_id) noexcept -> kphp::c auto res{co_await kphp::forks::id_managed(kphp::web::simple_transfer_reset(kphp::web::simple_transfer{easy_id}))}; if (!res.has_value()) [[unlikely]] { easy_ctx.set_errno(res.error().code, res.error().description); - kphp::web::curl::print_error("could not reset curl easy handle", std::move(res.error())); + kphp::web::curl::print_warning("could not reset curl easy handle", std::move(res.error())); co_return; } easy_ctx.reset(); @@ -475,7 +475,7 @@ inline auto f$curl_exec_concurrently(kphp::web::curl::easy_type easy_id, double auto sched_res{co_await kphp::coro::io_scheduler::get().schedule( kphp::forks::id_managed(kphp::web::simple_transfer_perform(kphp::web::simple_transfer{easy_id})), timeout)}; if (!sched_res.has_value()) [[unlikely]] { - kphp::web::curl::print_error( + kphp::web::curl::print_debug( "could not execute curl easy handle concurrently", kphp::web::error{.code = kphp::web::WEB_INTERNAL_ERROR_CODE, .description = string{"concurrent transfer has been interrupted due to timeout"}}); co_return false; @@ -484,7 +484,7 @@ inline auto f$curl_exec_concurrently(kphp::web::curl::easy_type easy_id, double easy_ctx.has_been_executed = true; if (!perform_res.has_value()) [[unlikely]] { easy_ctx.set_errno(perform_res.error().code, perform_res.error().description); - kphp::web::curl::print_error("could not execute curl easy handle concurrently", std::move(perform_res.error())); + kphp::web::curl::print_debug("could not execute curl easy handle concurrently", std::move(perform_res.error())); co_return false; } co_return std::move((*perform_res).body); @@ -525,7 +525,7 @@ inline auto f$curl_getinfo(kphp::web::curl::easy_type easy_id, int64_t option = kphp::web::get_transfer_properties(kphp::web::simple_transfer{easy_id}, std::nullopt, kphp::web::get_properties_policy::load))}; if (!res.has_value()) [[unlikely]] { easy_ctx.set_errno(res.error().code, res.error().description); - kphp::web::curl::print_error("could not get all info options of easy handle", std::move(res.error())); + kphp::web::curl::print_warning("could not get all info options of easy handle", std::move(res.error())); co_return false; } @@ -625,7 +625,7 @@ inline auto f$curl_getinfo(kphp::web::curl::easy_type easy_id, int64_t option = kphp::web::get_transfer_properties(kphp::web::simple_transfer{easy_id}, option, kphp::web::get_properties_policy::load))}; if (!res.has_value()) [[unlikely]] { easy_ctx.set_errno(res.error().code, res.error().description); - kphp::web::curl::print_error("could not get a specific info of easy handle", std::move(res.error())); + kphp::web::curl::print_warning("could not get a specific info of easy handle", std::move(res.error())); co_return 0; } const auto& v{(*res).find(option)}; diff --git a/runtime-light/stdlib/curl/curl-multi-functions.h b/runtime-light/stdlib/curl/curl-multi-functions.h index fbfb96a394..eec0116551 100644 --- a/runtime-light/stdlib/curl/curl-multi-functions.h +++ b/runtime-light/stdlib/curl/curl-multi-functions.h @@ -25,7 +25,7 @@ inline auto f$curl_multi_init() noexcept -> kphp::coro::task { auto open_res{co_await kphp::forks::id_managed(kphp::web::composite_transfer_open(kphp::web::transfer_backend::CURL))}; if (!open_res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not initialize a new curl multi handle", std::move(open_res.error())); + kphp::web::curl::print_warning("could not initialize a new curl multi handle", std::move(open_res.error())); co_return 0; } const auto descriptor{(*open_res).descriptor}; @@ -48,7 +48,7 @@ inline auto f$curl_multi_add_handle(kphp::web::curl::multi_type multi_id, kphp:: auto res{co_await kphp::forks::id_managed(kphp::web::composite_transfer_add(kphp::web::composite_transfer{multi_id}, kphp::web::simple_transfer{easy_id}))}; if (!res.has_value()) [[unlikely]] { multi_ctx.set_errno(res.error().code); - kphp::web::curl::print_error("could not add a curl easy handler into multi handle", std::move(res.error())); + kphp::web::curl::print_warning("could not add a curl easy handler into multi handle", std::move(res.error())); co_return multi_ctx.error_code; } multi_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -69,7 +69,7 @@ inline auto f$curl_multi_remove_handle(kphp::web::curl::multi_type multi_id, co_await kphp::forks::id_managed(kphp::web::composite_transfer_remove(kphp::web::composite_transfer{multi_id}, kphp::web::simple_transfer{easy_id}))}; if (!res.has_value()) [[unlikely]] { multi_ctx.set_errno(res.error().code); - kphp::web::curl::print_error("could not remove a curl easy handler from multi handle", std::move(res.error())); + kphp::web::curl::print_warning("could not remove a curl easy handler from multi handle", std::move(res.error())); co_return multi_ctx.error_code; } multi_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -94,7 +94,7 @@ inline auto f$curl_multi_setopt(kphp::web::curl::multi_type multi_id, int64_t op case kphp::web::curl::CURLPIPE::MULTIPLEX: { auto res{kphp::web::set_transfer_property(ct, option, kphp::web::property_value::as_long(std::to_underlying(pipeling_type)))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an mutli option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an mutli option", std::move(res.error())); return false; } multi_ctx.set_errno(kphp::web::curl::CURLME::OK); @@ -111,7 +111,7 @@ inline auto f$curl_multi_setopt(kphp::web::curl::multi_type multi_id, int64_t op case kphp::web::curl::CURMLOPT::MAX_TOTAL_CONNECTIONS: { auto res{kphp::web::set_transfer_property(ct, option, kphp::web::property_value::as_long(value))}; if (!res.has_value()) [[unlikely]] { - kphp::web::curl::print_error("could not set an multi option", std::move(res.error())); + kphp::web::curl::print_warning("could not set an multi option", std::move(res.error())); return false; } multi_ctx.set_errno(kphp::web::curl::CURLME::OK); @@ -132,7 +132,7 @@ inline auto f$curl_multi_exec(kphp::web::curl::multi_type multi_id, int64_t& sti auto& multi_ctx{curl_state.multi_ctx.get_or_init(multi_id)}; if (!res.has_value()) [[unlikely]] { multi_ctx.set_errno(res.error().code); - kphp::web::curl::print_error("could not execute curl multi handle", std::move(res.error())); + kphp::web::curl::print_warning("could not execute curl multi handle", std::move(res.error())); co_return multi_ctx.error_code; } still_running = (*res); @@ -150,7 +150,7 @@ inline auto f$curl_multi_getcontent(kphp::web::curl::easy_type easy_id) noexcept auto res{co_await kphp::forks::id_managed(kphp::web::simple_transfer_get_response(kphp::web::simple_transfer{easy_id}))}; if (!res.has_value()) [[unlikely]] { easy_ctx.set_errno(res.error().code); - kphp::web::curl::print_error("could not get response of curl easy handle", std::move(res.error())); + kphp::web::curl::print_warning("could not get response of curl easy handle", std::move(res.error())); co_return false; } co_return std::move((*res).body); @@ -167,7 +167,7 @@ inline auto f$curl_multi_close(kphp::web::curl::multi_type multi_id) noexcept -> auto res{co_await kphp::forks::id_managed(kphp::web::composite_transfer_close(kphp::web::composite_transfer{multi_id}))}; if (!res.has_value()) [[unlikely]] { multi_ctx.set_errno(res.error().code); - kphp::web::curl::print_error("could not close curl multi handle", std::move(res.error())); + kphp::web::curl::print_warning("could not close curl multi handle", std::move(res.error())); co_return; } multi_ctx.set_errno(kphp::web::curl::CURLE::OK); @@ -228,7 +228,7 @@ inline auto f$curl_multi_select(kphp::web::curl::multi_type multi_id, double tim kphp::web::composite_transfer{multi_id}, std::chrono::duration_cast(std::chrono::duration{timeout})))}; if (!res.has_value()) [[unlikely]] { multi_ctx.set_errno(res.error().code); - kphp::web::curl::print_error("could not select curl multi handle", std::move(res.error())); + kphp::web::curl::print_warning("could not select curl multi handle", std::move(res.error())); co_return multi_ctx.error_code; } co_return *res; @@ -248,7 +248,7 @@ inline auto f$curl_multi_info_read(kphp::web::curl::multi_type multi_id, kphp::web::get_transfer_properties(kphp::web::composite_transfer{multi_id}, CURL_MULTI_INFO_READ_OPTION, kphp::web::get_properties_policy::load))}; if (!props.has_value()) [[unlikely]] { multi_ctx.set_errno(props.error().code, props.error().description); - kphp::web::curl::print_error("could not get info message of multi handle", std::move(props.error())); + kphp::web::curl::print_warning("could not get info message of multi handle", std::move(props.error())); if (msgs_in_queue.has_value()) { (*msgs_in_queue).get() = 0; } @@ -257,7 +257,7 @@ inline auto f$curl_multi_info_read(kphp::web::curl::multi_type multi_id, auto it_optional_info{(*props).find(CURL_MULTI_INFO_READ_OPTION)}; if (it_optional_info == (*props).end()) [[unlikely]] { - kphp::web::curl::print_error("incorrect format of multi info message", std::move(props.error())); + kphp::web::curl::print_warning("incorrect format of multi info message", std::move(props.error())); if (msgs_in_queue.has_value()) { (*msgs_in_queue).get() = 0; } diff --git a/runtime-light/stdlib/curl/defs.h b/runtime-light/stdlib/curl/defs.h index 23c38ec22d..f2fbc49d45 100644 --- a/runtime-light/stdlib/curl/defs.h +++ b/runtime-light/stdlib/curl/defs.h @@ -19,7 +19,7 @@ enum class PHPCURL : uint64_t { using easy_type = simple_transfer::descriptor_type; using multi_type = composite_transfer::descriptor_type; -constexpr auto CURL_ERROR_SIZE = 256; +constexpr auto CURL_DIAGNOSTICS_MSG_SIZE = 256; enum class CURLE : uint16_t { OK = 0, diff --git a/runtime-light/stdlib/curl/details/diagnostics.h b/runtime-light/stdlib/curl/details/diagnostics.h index d4c2c680eb..be07edf81a 100644 --- a/runtime-light/stdlib/curl/details/diagnostics.h +++ b/runtime-light/stdlib/curl/details/diagnostics.h @@ -11,8 +11,8 @@ namespace kphp::web::curl { template -inline auto print_error(const char (&msg)[N], kphp::web::error&& e) noexcept { - static_assert(N <= CURL_ERROR_SIZE, "too long error"); +inline auto print_warning(const char (&msg)[N], kphp::web::error&& e) noexcept { + static_assert(N <= CURL_DIAGNOSTICS_MSG_SIZE, "too long error"); if (e.description.has_value()) { kphp::log::warning("{}\ncode: {}; description: {}", msg, e.code, (*e.description).c_str()); } else { @@ -20,4 +20,14 @@ inline auto print_error(const char (&msg)[N], kphp::web::error&& e) noexcept { } } +template +inline auto print_debug(const char (&msg)[N], kphp::web::error&& e) noexcept { + static_assert(N <= CURL_DIAGNOSTICS_MSG_SIZE, "too long error"); + if (e.description.has_value()) { + kphp::log::debug("{}\ncode: {}; description: {}", msg, e.code, (*e.description).c_str()); + } else { + kphp::log::debug("{}: {}", msg, e.code); + } +} + } // namespace kphp::web::curl