Skip to content

Commit e94862a

Browse files
committed
use string as RPC response instead of vector
1 parent afe86c1 commit e94862a

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

runtime-light/stdlib/rpc/rpc-api.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
#include "common/containers/final_action.h"
2121
#include "common/rpc-error-codes.h"
22-
#include "runtime-common/core/allocator/script-allocator.h"
2322
#include "runtime-common/core/runtime-core.h"
24-
#include "runtime-common/core/std/containers.h"
2523
#include "runtime-light/allocator/allocator.h"
2624
#include "runtime-light/coroutine/io-scheduler.h"
2725
#include "runtime-light/coroutine/task.h"
@@ -207,7 +205,7 @@ kphp::coro::task<array<mixed>> rpc_tl_query_result_one_impl(int64_t query_id) no
207205
co_return TlRpcError::make_error(TL_ERROR_INTERNAL, string{"can't get untyped result from typed TL query. Use consistent API for that"});
208206
}
209207

210-
auto opt_response{co_await kphp::forks::wait<kphp::stl::vector<std::byte, kphp::memory::script_allocator>>(response_waiter_fork_id, MAX_TIMEOUT_NS)};
208+
auto opt_response{co_await kphp::forks::wait<string>(response_waiter_fork_id, MAX_TIMEOUT_NS)};
211209
if (!opt_response) [[unlikely]] {
212210
co_return TlRpcError::make_error(TL_ERROR_INTERNAL, string{"can't find waiter fork"});
213211
}
@@ -217,7 +215,7 @@ kphp::coro::task<array<mixed>> rpc_tl_query_result_one_impl(int64_t query_id) no
217215
}
218216

219217
f$rpc_clean();
220-
RpcServerInstanceState::get().tl_fetcher = tl::fetcher{response};
218+
RpcServerInstanceState::get().tl_fetcher = tl::fetcher{{reinterpret_cast<const std::byte*>(response.c_str()), response.size()}};
221219
auto res{fetch_function_untyped(rpc_query)}; // THROWING
222220
// handle exceptions that could arise during fetch_function_untyped
223221
if (auto err{TlRpcError::transform_exception_into_error_if_possible()}; !err.empty()) [[unlikely]] {
@@ -260,7 +258,7 @@ kphp::coro::task<class_instance<C$VK$TL$RpcResponse>> typed_rpc_tl_query_result_
260258
co_return error_factory.make_error(TL_ERROR_INTERNAL, string{"can't get typed result from untyped TL query. Use consistent API for that"});
261259
}
262260

263-
auto opt_response{co_await kphp::forks::wait<kphp::stl::vector<std::byte, kphp::memory::script_allocator>>(response_waiter_fork_id, MAX_TIMEOUT_NS)};
261+
auto opt_response{co_await kphp::forks::wait<string>(response_waiter_fork_id, MAX_TIMEOUT_NS)};
264262
if (!opt_response) [[unlikely]] {
265263
co_return error_factory.make_error(TL_ERROR_INTERNAL, string{"can't find waiter fork"});
266264
}
@@ -270,7 +268,7 @@ kphp::coro::task<class_instance<C$VK$TL$RpcResponse>> typed_rpc_tl_query_result_
270268
}
271269

272270
f$rpc_clean();
273-
RpcServerInstanceState::get().tl_fetcher = tl::fetcher{response};
271+
RpcServerInstanceState::get().tl_fetcher = tl::fetcher{{reinterpret_cast<const std::byte*>(response.c_str()), response.size()}};
274272
auto res{fetch_function_typed(rpc_query, error_factory)}; // THROWING
275273
// handle exceptions that could arise during fetch_function_typed
276274
if (auto err{error_factory.transform_exception_into_error_if_possible()}; !err.is_null()) [[unlikely]] {
@@ -331,11 +329,11 @@ kphp::coro::task<kphp::rpc::query_info> send_request(std::string_view actor, std
331329
// create fork to wait for RPC response. we need to do it even if 'ignore_answer' is 'true' to make sure
332330
// that the stream will not be closed too early. otherwise, platform may even not send RPC request
333331
auto awaiter_task{[](int64_t query_id, kphp::component::stream stream, std::chrono::nanoseconds timeout,
334-
bool collect_responses_extra_info) noexcept -> kphp::coro::task<kphp::stl::vector<std::byte, kphp::memory::script_allocator>> {
335-
kphp::stl::vector<std::byte, kphp::memory::script_allocator> response{};
332+
bool collect_responses_extra_info) noexcept -> kphp::coro::task<string> {
333+
string response{};
336334
auto fetch_task{kphp::component::fetch_response(stream, kphp::component::read_ext::append(response))};
337335
if (auto expected{co_await kphp::coro::io_scheduler::get().schedule(std::move(fetch_task), timeout)}; !expected) [[unlikely]] {
338-
response.clear();
336+
response = {};
339337
}
340338

341339
// update response extra info if needed

0 commit comments

Comments
 (0)