asio-grpc v3.1.0
Asynchronous gRPC with Asio/unified executors
agrpc::ServerRPC< RequestBidiStreaming, TraitsT, Executor > Class Template Reference

I/O object for server-side, bidirectional-streaming rpcs. More...

#include <agrpc/server_rpc.hpp>

Inherits agrpc::detail::ServerRPCBidiStreamingBase< Responder, Traits, Executor >.

Classes

struct  rebind_executor
 Rebind the ServerRPC to another executor. More...
 

Public Types

using Ptr = agrpc::ServerRPCPtr< ServerRPC >
 ServerRPCPtr specialized on this type.
 

Public Member Functions

 ServerRPC ()=delete
 Deleted default constructor.
 

Static Public Member Functions

static constexpr std::string_view service_name () noexcept
 Name of the gRPC service. More...
 
static constexpr std::string_view method_name () noexcept
 Name of the gRPC method. More...
 

Static Public Attributes

static constexpr agrpc::ServerRPCType TYPE = agrpc::ServerRPCType::BIDIRECTIONAL_STREAMING
 The rpc type.
 

Detailed Description

template<class ServiceT, class RequestT, class ResponseT, detail::ServerBidiStreamingRequest< ServiceT, RequestT, ResponseT > RequestBidiStreaming, class TraitsT, class Executor>
class agrpc::ServerRPC< RequestBidiStreaming, TraitsT, Executor >

I/O object for server-side, bidirectional-streaming rpcs.

Use one of the agrpc::register_ functions to set up request handling.

Example:

void server_rpc_bidirectional_streaming(agrpc::GrpcContext& grpc_context,
example::v1::Example::AsyncService& service)
{
using RPC = asio::use_awaitable_t<>::as_default_on_t<agrpc::ServerRPC<
&example::v1::Example::AsyncService::RequestBidirectionalStreaming>>;
agrpc::register_awaitable_rpc_handler<RPC>(
grpc_context, service,
[](RPC& rpc) -> asio::awaitable<void>
{
RPC::Request request;
RPC::Response response;
while (co_await rpc.read(request))
{
response.set_integer(request.integer());
if (!co_await rpc.write(response))
{
co_return;
}
}
response.set_integer(42);
co_await rpc.write(response, grpc::WriteOptions{}.set_last_message());
co_await rpc.finish(grpc::Status::OK);
},
asio::detached);
}
Execution context based on grpc::CompletionQueue
Definition: grpc_context.hpp:50
Primary ServerRPC template.
Definition: forward.hpp:76

Based on .proto file:

syntax = "proto3";
package example.v1;
service Example {
rpc ServerStreaming(Request) returns (stream Response) {}
rpc ClientStreaming(stream Request) returns (Response) {}
rpc BidirectionalStreaming(stream Request) returns (stream Response) {}
rpc Unary(Request) returns (Response) {}
}
message Request {
int32 integer = 1;
}
message Response {
int32 integer = 1;
}
Template Parameters
RequestUnaryA pointer to the generated gRPC method.
TraitsA type used to customize this rpc. See agrpc::DefaultServerRPCTraits.
ExecutorThe executor type, must be capable of referring to a agrpc::GrpcContext.

Per-Operation Cancellation

(except wait_for_done) Terminal and partial. Cancellation is performed by invoking grpc::ServerContext::TryCancel. After successful cancellation no further operations should be started on the rpc. Operations are also cancelled when the deadline of the rpc has been reached.

Since
2.7.0

Member Function Documentation

◆ service_name()

template<class ServiceT , class RequestT , class ResponseT , detail::ServerBidiStreamingRequest< ServiceT, RequestT, ResponseT > RequestBidiStreaming, class TraitsT , class Executor >
static constexpr std::string_view agrpc::ServerRPC< RequestBidiStreaming, TraitsT, Executor >::service_name ( )
inlinestaticconstexprnoexcept

Name of the gRPC service.

Equal to the generated Service::service_full_name().

E.g. for the .proto schema

package example.v1;
service Example { ... }

the return value would be "example.v1.Example".

◆ method_name()

template<class ServiceT , class RequestT , class ResponseT , detail::ServerBidiStreamingRequest< ServiceT, RequestT, ResponseT > RequestBidiStreaming, class TraitsT , class Executor >
static constexpr std::string_view agrpc::ServerRPC< RequestBidiStreaming, TraitsT, Executor >::method_name ( )
inlinestaticconstexprnoexcept

Name of the gRPC method.

E.g. for agrpc::ServerRPC<&example::Example::AsyncService::RequestMyMethod> the return value would be "MyMethod".