diff --git a/example/snippets/server_rpc.cpp b/example/snippets/server_rpc.cpp index 6977365c..83d13ab6 100644 --- a/example/snippets/server_rpc.cpp +++ b/example/snippets/server_rpc.cpp @@ -267,18 +267,11 @@ class RPCHandlerWithArenaRequestMessageFactory public: explicit RPCHandlerWithArenaRequestMessageFactory(Handler handler) : handler_(std::move(handler)) {} - // unary and server-streaming rpcs - template - decltype(auto) operator()(ServerRPC&& rpc, Request&& request, ArenaRequestMessageFactory&) + template + decltype(auto) operator()(Args&&... args) { - return handler_(std::forward(rpc), std::forward(request)); - } - - // client-streaming and bidi-streaming rpcs - template - decltype(auto) operator()(ServerRPC&& rpc) - { - return handler_(std::forward(rpc)); + // for unary and server-streaming rpcs args are: ServerRPC&, Request&, ArenaRequestMessageFactory& + return handler_(std::forward(args)...); } ArenaRequestMessageFactory request_message_factory() { return {}; } @@ -287,16 +280,12 @@ class RPCHandlerWithArenaRequestMessageFactory Handler handler_; }; -template -void register_rpc_handler(agrpc::GrpcContext& grpc_context, example::v1::Example::AsyncService& service) +template +void register_rpc_handler(agrpc::GrpcContext& grpc_context, example::v1::Example::AsyncService& service, + RPCHandler&& handler) { agrpc::register_awaitable_rpc_handler( - grpc_context, service, - RPCHandlerWithArenaRequestMessageFactory{[&](ServerRPC&, typename ServerRPC::Request&) -> asio::awaitable - { - // ... - co_return; - }}, + grpc_context, service, RPCHandlerWithArenaRequestMessageFactory{std::forward(handler)}, asio::detached); } /* [server-rpc-handler-with-arena] */ diff --git a/src/agrpc/detail/register_sender_rpc_handler.hpp b/src/agrpc/detail/register_sender_rpc_handler.hpp index 48ea28eb..dd4d109e 100644 --- a/src/agrpc/detail/register_sender_rpc_handler.hpp +++ b/src/agrpc/detail/register_sender_rpc_handler.hpp @@ -157,6 +157,7 @@ struct RPCHandlerOperation { using Service = detail::ServerRPCServiceT; using Traits = typename ServerRPC::Traits; + using Starter = detail::ServerRPCStarter<>; using RequestMessageFactory = detail::ServerRPCRequestMessageFactoryT; using RPCHandlerInvokeResult = detail::RPCHandlerInvokeResultT; using RegisterRPCHandlerSenderOperationBase = @@ -206,10 +207,10 @@ struct RPCHandlerOperation #endif }; - using StartOperationState = detail::InplaceWithFunctionWrapper::start(std::declval(), std::declval(), - std::declval(), agrpc::use_sender)), - StartReceiver>>; + using StartOperationState = detail::InplaceWithFunctionWrapper< + exec::connect_result_t(), std::declval(), + std::declval(), agrpc::use_sender)), + StartReceiver>>; template struct Receiver @@ -270,7 +271,8 @@ struct RPCHandlerOperation detail::InplaceWithFunction{}, [&] { - return starter().start(rpc_, operation.service(), agrpc::use_sender).connect(StartReceiver{*this}); + return Starter::start(rpc_, operation.service(), request_message_factory(), agrpc::use_sender) + .connect(StartReceiver{*this}); }) { base().increment_ref_count(); @@ -304,7 +306,8 @@ struct RPCHandlerOperation detail::InplaceWithFunction{}, [&] { - return exec::connect(starter().invoke(rpc_handler(), rpc_), FinishReceiver{*this}); + return exec::connect(Starter::invoke(rpc_handler(), rpc_, request_message_factory()), + FinishReceiver{*this}); }); return {}; } @@ -331,7 +334,7 @@ struct RPCHandlerOperation auto& rpc_handler() noexcept { return base().rpc_handler(); } - auto& starter() noexcept { return impl1_.second(); } + auto& request_message_factory() noexcept { return impl1_.second(); } auto& operation_state() noexcept { return impl2_.first(); }