Add asynchronous RPC support to asio_rpc, co20_rpc and coro_rpc backends#88
Merged
Conversation
Mirror the co::Coroutine async RPC feature for the Boost.Asio (stackful yield_context) backend. - Add backend-agnostic rpc/common/shared_ptr_pipe_base.h providing pipe fd management, non-blocking byte transfer primitives, and the shared_ptr in-transit reference codec, so co20_rpc/coro_rpc can reuse it later. - Add asio_rpc/common/shared_ptr_pipe.h: a SharedPtrPipe<T> driven by boost::asio::yield_context built on the shared base. - Add RegisterMethodAsync, ReplyItem/ReplyQueue, and split the non-streaming method handling into SessionRequestCoroutine + SessionResponseCoroutine communicating over the pipe. The synchronous RegisterMethod overloads now delegate to the async path. - Add a CallAsyncMethod server test. - Add a CMake build for asio_rpc behind the new SUBSPACE_ASIO_RPC option (default on, auto-disabled when cross-compiling), fetching Boost via FetchContent.
Port the async RPC feature to the C++20 stackless coroutine (co20) backend,
reusing the backend-agnostic rpc/common/shared_ptr_pipe_base.h.
- Add co20_rpc/common/shared_ptr_pipe.h: a SharedPtrPipe<T> with a co20
ValueTask Read (suspends on the pipe via co20::Wait, reports shutdown as a
CancelledError) and a synchronous non-blocking Write. Read yields its value
through an out parameter because co20::ValueTask<T> requires T to be
default-constructible (absl::StatusOr is not).
- Add RegisterMethodAsync, ReplyItem/ReplyQueue, and split the non-streaming
method handling into SessionRequestCoroutine + SessionResponseCoroutine
communicating over the pipe. The synchronous RegisterMethod overloads now
delegate to the async path.
- Add a CallAsyncMethod server test.
- Add a CMake build for co20_rpc behind the new SUBSPACE_CO20_RPC option
(default on, skipped when cross-compiling without the host plugin). co20
targets are compiled as C++20.
- Fix a generated-stub header collision in both the asio_rpc and co20_rpc
CMake builds: the rpc/ co-flavored "rpc/proto/rpc_test.subspace.*.h" under
${CMAKE_BINARY_DIR} was shadowing the backend-flavored stubs, so prepend each
backend's gen root to the directory include path.
Port the async RPC pipeline to the C++20 boost::asio::awaitable backend, matching the asio_rpc and co20_rpc implementations. - Add coro_rpc::SharedPtrPipe<T> (coro_rpc/common/shared_ptr_pipe.h) on top of the backend-agnostic rpc_internal::SharedPtrPipeBase, with an awaited Read returning awaitable<StatusOr<shared_ptr>> and a synchronous, non-blocking Write (a coro handler's reply callback cannot co_await). - Add internal::ReplyItem/ReplyQueue and RegisterMethodAsync; the existing synchronous RegisterMethod overloads now delegate to the async path. - Replace SessionMethodCoroutine with a two-coroutine pipeline: SessionRequestCoroutine invokes the (possibly async) handler whose reply/error callbacks enqueue into the pipe, and SessionResponseCoroutine drains the pipe and publishes responses. - Add a CallAsyncMethod server test exercising an async handler that suspends on a timer before replying. - Wire the new pipe and dependencies into Bazel and add coro_rpc/CMakeLists.txt (C++20, Boost.Asio, rpc_style=coro), gated on SUBSPACE_ASIO_RPC. All Bazel and CMake tests pass across rpc, asio_rpc, co20_rpc and coro_rpc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports the asynchronous RPC pipeline (previously added to the
co::Coroutinerpc/backend in #86) to the three remaining C++ RPC backends —asio_rpc(Boost.Asio stackfulyield_context),co20_rpc(C++20 stacklessco::Coroutineruntime) andcoro_rpc(C++20boost::asio::awaitable).rpc_internal::SharedPtrPipeBase(rpc/common/shared_ptr_pipe_base.h) that owns the non-blocking pipe fds, raw read/write, andstd::shared_ptr(de)serialization with in-transit reference semantics. Each backend wraps it with its own asyncSharedPtrPipe<T>:asio_rpc:Read/Writesuspend viayield_context.co20_rpc:Readis aco20::ValueTask<absl::Status>with ashared_ptrout-param (ValueTask needs a default-constructible type);Writeis synchronous and non-blocking.coro_rpc:Readis awaited and returnsawaitable<StatusOr<shared_ptr>>;Writeis synchronous and non-blocking.internal::ReplyItem/ReplyQueueandRegisterMethodAsync; the existing synchronousRegisterMethodoverloads now delegate to the async path.CallAsyncMethodserver test per backend exercising a handler that suspends (timer/sleep) before replying.asio_rpc/,co20_rpc/andcoro_rpc/CMakeLists.txtfiles.asio_rpcandcoro_rpcare gated onSUBSPACE_ASIO_RPC(where Boost is fetched);co20_rpconSUBSPACE_CO20_RPC.Test plan
bazelisk test //rpc/... //asio_rpc/... //co20_rpc/... //coro_rpc/...— all 12 tests pass.asio_rpc,co20_rpcandcoro_rpcbackends locally.