Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::byte, kphp::memory::script_allocator> sink_buffer{size};
std::span<std::byte> sink_resp{sink_buffer.data(), sink_buffer.size()};
Expand Down
17 changes: 9 additions & 8 deletions runtime-light/stdlib/curl/curl-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cstddef>
#include <cstdint>
#include <optional>
#include <utility>

#include "common/mixin/movable_only.h"
#include "runtime-common/core/runtime-core.h"
Expand All @@ -18,15 +19,15 @@ namespace kphp::web::curl {

struct curl_context : vk::movable_only {
int64_t error_code{0};
std::array<std::byte, kphp::web::curl::CURL_ERROR_SIZE> error_description{std::byte{0}};
std::array<std::byte, kphp::web::curl::CURL_DIAGNOSTICS_MSG_SIZE> error_description{std::byte{0}};

inline auto set_errno(int64_t code, std::string_view description) noexcept {
// If Web Transfer Lib specific error
if (code == kphp::web::WEB_INTERNAL_ERROR_CODE) [[unlikely]] {
return;
}
error_code = static_cast<int64_t>(code);
std::memcpy(error_description.data(), description.data(), std::min(description.size(), static_cast<size_t>(CURL_ERROR_SIZE)));
error_code = code;
std::memcpy(error_description.data(), description.data(), std::min(description.size(), static_cast<size_t>(CURL_DIAGNOSTICS_MSG_SIZE)));
}

inline auto set_errno(int64_t code, std::optional<string> description = std::nullopt) noexcept {
Expand All @@ -38,24 +39,24 @@ struct curl_context : vk::movable_only {
}

inline auto set_errno(kphp::web::curl::CURLE code, std::string_view description) noexcept {
set_errno(static_cast<int64_t>(code), description);
set_errno(std::to_underlying(code), description);
}

inline auto set_errno(kphp::web::curl::CURLE code, std::optional<string> description = std::nullopt) noexcept {
set_errno(static_cast<int64_t>(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<int64_t>(code), description);
set_errno(std::to_underlying(code), description);
}

inline auto set_errno(kphp::web::curl::CURLME code, std::optional<string> description = std::nullopt) noexcept {
set_errno(static_cast<int64_t>(code), std::move(description));
set_errno(std::to_underlying(code), std::move(description));
}

template<size_t N>
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}});
}
Expand Down
112 changes: 57 additions & 55 deletions runtime-light/stdlib/curl/curl-easy-functions.h

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions runtime-light/stdlib/curl/curl-multi-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cstdint>
#include <functional>
#include <optional>
#include <utility>

#include "runtime-common/core/runtime-core.h"
#include "runtime-light/coroutine/task.h"
Expand All @@ -17,14 +18,14 @@
#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<kphp::web::curl::multi_type> {
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};
Expand All @@ -47,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);
Expand All @@ -68,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);
Expand All @@ -91,9 +92,9 @@ 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<int64_t>(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()));
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);
Expand All @@ -110,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);
Expand All @@ -131,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);
Expand All @@ -149,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);
Expand All @@ -166,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);
Expand Down Expand Up @@ -227,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::seconds>(std::chrono::duration<double>{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;
Expand All @@ -247,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;
}
Expand All @@ -256,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;
}
Expand Down Expand Up @@ -290,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));
}
}

Expand Down
Loading
Loading