asio-grpc v3.3.0
Asynchronous gRPC with Asio/unified executors
|
Public namespace. More...
Classes | |
class | BasicAlarm |
I/O object for grpc::Alarm More... | |
class | BasicGrpcExecutor |
GrpcContext's executor. More... | |
class | ClientRPC |
Primary ClientRPC template. More... | |
class | ClientRPC< agrpc::ClientRPCType::GENERIC_STREAMING, Executor > |
I/O object for client-side, generic, streaming rpcs. More... | |
class | ClientRPC< agrpc::ClientRPCType::GENERIC_UNARY, Executor > |
I/O object for client-side, generic, unary rpcs. More... | |
class | ClientRPC< PrepareAsyncBidiStreaming, Executor > |
I/O object for client-side, bidirectional-streaming rpcs. More... | |
class | ClientRPC< PrepareAsyncClientStreaming, Executor > |
I/O object for client-side, client-streaming rpcs. More... | |
class | ClientRPC< PrepareAsyncServerStreaming, Executor > |
I/O object for client-side, server-streaming rpcs. More... | |
class | ClientRPC< PrepareAsyncUnary, Executor > |
I/O object for client-side, unary rpcs. More... | |
struct | DefaultRunTraits |
(experimental) Default run traits More... | |
struct | DefaultServerRPCTraits |
Default ServerRPC traits. More... | |
class | GrpcContext |
Execution context based on grpc::CompletionQueue More... | |
class | HealthCheckService |
CompletionQueue-based implementation of grpc::HealthCheckServiceInterface. More... | |
class | ServerRPC |
Primary ServerRPC template. More... | |
class | ServerRPC< agrpc::ServerRPCType::GENERIC, TraitsT, Executor > |
I/O object for server-side, generic rpcs. More... | |
class | ServerRPC< RequestBidiStreaming, TraitsT, Executor > |
I/O object for server-side, bidirectional-streaming rpcs. More... | |
class | ServerRPC< RequestClientStreaming, TraitsT, Executor > |
I/O object for server-side, client-streaming rpcs. More... | |
class | ServerRPC< RequestServerStreaming, TraitsT, Executor > |
I/O object for server-side, server-streaming rpcs. More... | |
class | ServerRPC< RequestUnary, TraitsT, Executor > |
I/O object for server-side, unary rpcs. More... | |
class | ServerRPCPtr |
Allocated ServerRPC created by register_callback_rpc_handler. More... | |
struct | UseSender |
Sender completion token. More... | |
class | Waiter |
(experimental) Utility class for uncancelable operations More... | |
Typedefs | |
using | Alarm = agrpc::BasicAlarm<agrpc::GrpcExecutor> |
A BasicAlarm that uses agrpc::GrpcExecutor | |
using | GenericUnaryClientRPC = agrpc::ClientRPC<agrpc::ClientRPCType::GENERIC_UNARY> |
I/O object for client-side, generic, unary rpcs (type alias) | |
using | GenericStreamingClientRPC = agrpc::ClientRPC<agrpc::ClientRPCType::GENERIC_STREAMING> |
I/O object for client-side, generic, streaming rpcs (type alias) | |
using | GrpcExecutor = agrpc::BasicGrpcExecutor<> |
Default GrpcExecutor. | |
using | GenericServerRPC = agrpc::ServerRPC<agrpc::ServerRPCType::GENERIC> |
I/O object for server-side, generic rpcs (type alias) | |
Enumerations | |
enum class | ClientRPCType { UNARY , GENERIC_UNARY , SERVER_STREAMING , CLIENT_STREAMING , BIDIRECTIONAL_STREAMING , GENERIC_STREAMING } |
The type of a ClientRPC. More... | |
enum class | ServerRPCType { UNARY , SERVER_STREAMING , CLIENT_STREAMING , BIDIRECTIONAL_STREAMING , GENERIC } |
The type of a ServerRPC. More... | |
Functions | |
template<class ServerRPC , class RPCHandler , class CompletionToken = detail::DefaultCompletionTokenT<typename ServerRPC::executor_type>> | |
auto | register_awaitable_rpc_handler (const typename ServerRPC::executor_type &executor, detail::ServerRPCServiceT< ServerRPC > &service, RPCHandler rpc_handler, CompletionToken &&token=CompletionToken{}) |
Register an awaitable rpc handler for the given method. | |
template<class ServerRPC , class RPCHandler , class CompletionToken > | |
auto | register_awaitable_rpc_handler (agrpc::GrpcContext &grpc_context, detail::ServerRPCServiceT< ServerRPC > &service, RPCHandler &&rpc_handler, CompletionToken &&token) |
Register an awaitable rpc handler for the given method (GrpcContext overload) | |
template<class ServerRPC , class RPCHandler , class CompletionToken = detail::DefaultCompletionTokenT<typename ServerRPC::executor_type>> | |
auto | register_callback_rpc_handler (const typename ServerRPC::executor_type &executor, detail::ServerRPCServiceT< ServerRPC > &service, RPCHandler rpc_handler, CompletionToken &&token=CompletionToken{}) |
Register a callback rpc handler for the given method. | |
template<class ServerRPC , class RPCHandler , class CompletionToken > | |
auto | register_callback_rpc_handler (agrpc::GrpcContext &grpc_context, detail::ServerRPCServiceT< ServerRPC > &service, RPCHandler &&rpc_handler, CompletionToken &&token) |
Register a callback rpc handler for the given method (GrpcContext overload) | |
template<class ServerRPC , class CoroutineTraits , class RPCHandler , class CompletionToken = detail::DefaultCompletionTokenT<typename ServerRPC::executor_type>> | |
auto | register_coroutine_rpc_handler (const typename ServerRPC::executor_type &executor, detail::ServerRPCServiceT< ServerRPC > &service, RPCHandler rpc_handler, CompletionToken &&token=CompletionToken{}) |
(experimental) Register a coroutine rpc handler for the given method | |
template<class ServerRPC , class CoroutineTraits , class RPCHandler , class CompletionToken > | |
auto | register_coroutine_rpc_handler (agrpc::GrpcContext &grpc_context, detail::ServerRPCServiceT< ServerRPC > &service, RPCHandler &&rpc_handler, CompletionToken &&token) |
(experimental) Register an coroutine rpc handler for the given method (GrpcContext overload) | |
template<class ServerRPC , class RPCHandler > | |
detail::RPCHandlerSender< ServerRPC, RPCHandler > | register_sender_rpc_handler (agrpc::GrpcContext &grpc_context, detail::ServerRPCServiceT< ServerRPC > &service, RPCHandler rpc_handler) |
Register a sender rpc handler for the given method. | |
template<class ServerRPC , class RPCHandler , class CompletionToken = detail::DefaultCompletionTokenT<typename ServerRPC::executor_type>> | |
auto | register_yield_rpc_handler (const typename ServerRPC::executor_type &executor, detail::ServerRPCServiceT< ServerRPC > &service, RPCHandler rpc_handler, CompletionToken &&token=CompletionToken{}) |
Register a Boost.Coroutine rpc handler for the given method. | |
template<class ServerRPC , class RPCHandler , class CompletionToken > | |
auto | register_yield_rpc_handler (agrpc::GrpcContext &grpc_context, detail::ServerRPCServiceT< ServerRPC > &service, RPCHandler &&rpc_handler, CompletionToken &&token) |
Register a rpc handler for the given method (GrpcContext overload) | |
template<class Traits = agrpc::DefaultRunTraits, class ExecutionContext = void> | |
void | run (agrpc::GrpcContext &grpc_context, ExecutionContext &execution_context) |
(experimental) Run an execution context in the same thread as a GrpcContext | |
template<class Traits = agrpc::DefaultRunTraits, class ExecutionContext = void, class StopCondition = void> | |
void | run (agrpc::GrpcContext &grpc_context, ExecutionContext &execution_context, StopCondition stop_condition) |
(experimental) Run an execution context in the same thread as a GrpcContext | |
template<class Traits = agrpc::DefaultRunTraits, class ExecutionContext = void> | |
void | run_completion_queue (agrpc::GrpcContext &grpc_context, ExecutionContext &execution_context) |
(experimental) Run an execution context in the same thread as a GrpcContext's completion queue | |
template<class Traits = agrpc::DefaultRunTraits, class ExecutionContext = void, class StopCondition = void> | |
void | run_completion_queue (agrpc::GrpcContext &grpc_context, ExecutionContext &execution_context, StopCondition stop_condition) |
(experimental) Run an execution context in the same thread as a GrpcContext's completion queue | |
void | process_grpc_tag (agrpc::GrpcContext &grpc_context, void *tag, bool ok) |
Test utility to manually process gRPC tags. | |
grpc::ServerBuilder & | add_health_check_service (grpc::ServerBuilder &builder) |
Add a HealthCheckService to a grpc::Server | |
void | start_health_check_service (agrpc::HealthCheckService &service, agrpc::GrpcContext &grpc_context) |
Start a previously added HealthCheckService. | |
void | start_health_check_service (grpc::Server &server, agrpc::GrpcContext &grpc_context) |
Start a previously added HealthCheckService (grpc::Server overload) | |
Variables | |
constexpr detail::NotifyOnStateChangeFn | notify_on_state_change {} |
Set notification for a grpc::Channel state change. | |
constexpr detail::ReadFn | read {} |
Read from a streaming RPC. | |
constexpr agrpc::UseSender | use_sender {} |
Instance and factory for sender completion tokens. | |
Public namespace.
A BasicAlarm that uses agrpc::GrpcExecutor
I/O object for client-side, generic, unary rpcs (type alias)
I/O object for client-side, generic, streaming rpcs (type alias)
using agrpc::GrpcExecutor = agrpc::BasicGrpcExecutor<> |
Default GrpcExecutor.
The default GrpcExecutor does not track outstanding work, has the relationship.fork and blocking.never properties and uses the default allocator (std::allocator<void>
).
I/O object for server-side, generic rpcs (type alias)
|
strong |
The type of a ClientRPC.
|
strong |
The type of a ServerRPC.
auto agrpc::register_awaitable_rpc_handler | ( | const typename ServerRPC::executor_type & | executor, |
detail::ServerRPCServiceT< ServerRPC > & | service, | ||
RPCHandler | rpc_handler, | ||
CompletionToken && | token = CompletionToken{} ) |
Register an awaitable rpc handler for the given method.
The rpc handler will be invoked for every incoming request of this gRPC method. It must take ServerRPC&
as first argument and ServerRPC::Request&
as second argument (only for unary and server-streaming rpcs). The ServerRPC is automatically cancelled at the end of the rpc handler if finish()
was not called earlier. The return value of the rpc handler is co_spawn
ed in a manner similar to: asio::co_spawn(asio::get_associated_executor(completion_handler, executor), rpc_handler)
, where completion_handler
is created from token
and executor
the first argument passed to this function.
This asynchronous operation runs forever unless it is cancelled, the rpc handler throws an exception or the server is shutdown (grpc::Server::Shutdown is called). At which point it invokes the completion handler (passing forward the exception thrown by the request handler, if any) after all awaitables produced by invoking the rpc handler complete.
Example:
ServerRPC | An instantiation of agrpc::ServerRPC |
executor | The executor used to handle each rpc |
service | The service associated with the gRPC method of the ServerRPC |
rpc_handler | A callable that produces an asio::awaitable<void, Executor> . The awaitable's return value is ignored. The Executor must be constructible from asio::get_associated_executor(completion_handler,
executor) , where completion_handler is obtained from token and executor the first argument passed to this function. |
token | A completion token for signature void(std::exception_ptr) . |
auto agrpc::register_awaitable_rpc_handler | ( | agrpc::GrpcContext & | grpc_context, |
detail::ServerRPCServiceT< ServerRPC > & | service, | ||
RPCHandler && | rpc_handler, | ||
CompletionToken && | token ) |
Register an awaitable rpc handler for the given method (GrpcContext overload)
auto agrpc::register_callback_rpc_handler | ( | const typename ServerRPC::executor_type & | executor, |
detail::ServerRPCServiceT< ServerRPC > & | service, | ||
RPCHandler | rpc_handler, | ||
CompletionToken && | token = CompletionToken{} ) |
Register a callback rpc handler for the given method.
The rpc handler will be invoked for every incoming request of this gRPC method. It must take ServerRPC::Ptr
as first and ServerRPC::Request&
as second (only for unary and server-streaming rpcs) argument. The ServerRPC is automatically cancelled during destruction of the ServerRPC::Ptr
if finish()
was not called earlier.
This asynchronous operation runs forever unless it is cancelled, the rpc handler throws an exception or the server is shutdown (grpc::Server::Shutdown is called). At which point it invokes the completion handler (passing forward the exception thrown by the request handler, if any) after all ServerRPC::Ptr
s have been destructed.
Example:
ServerRPC | An instantiation of agrpc::ServerRPC |
executor | The executor used to handle each rpc |
service | The service associated with the gRPC method of the ServerRPC |
rpc_handler | A callable that handles the client's request |
token | A completion token for signature void(std::exception_ptr) . |
auto agrpc::register_callback_rpc_handler | ( | agrpc::GrpcContext & | grpc_context, |
detail::ServerRPCServiceT< ServerRPC > & | service, | ||
RPCHandler && | rpc_handler, | ||
CompletionToken && | token ) |
Register a callback rpc handler for the given method (GrpcContext overload)
auto agrpc::register_coroutine_rpc_handler | ( | const typename ServerRPC::executor_type & | executor, |
detail::ServerRPCServiceT< ServerRPC > & | service, | ||
RPCHandler | rpc_handler, | ||
CompletionToken && | token = CompletionToken{} ) |
(experimental) Register a coroutine rpc handler for the given method
The rpc handler will be invoked for every incoming request of this gRPC method. It must take ServerRPC&
as first argument and ServerRPC::Request&
as second argument (only for unary and server-streaming rpcs). The ServerRPC is automatically cancelled at the end of the rpc handler if finish()
was not called earlier. The return value of the rpc handler is co_spawn
ed in a manner similar to: CoroutineTraits::co_spawn(executor, rpc_handler, completion_handler, function)
, where completion_handler
is created from token
, executor
the first argument passed to this function and function
, when invoked, starts waiting for the next rpc. Any arguments passed to function
will be prepended to the call of the rpc handler. The return type of function
is CoroutineTraits::ReturnType
, which must be a coroutine, and CoroutineTraits::completion_token
must produce an Asio compatible completion token that, when used to initiate an asynchronous operation, returns an awaitable.
This asynchronous operation runs forever unless it is cancelled, the rpc handler throws an exception or the server is shutdown (grpc::Server::Shutdown is called). At which point it invokes the completion handler (passing forward the exception thrown by the request handler, if any) after all coroutines produced by invoking the rpc handler complete.
ServerRPC | An instantiation of agrpc::ServerRPC |
CoroutineTraits | A class that provides functions for spawning the coroutine of each rpc. Example: |
executor | The executor used to handle each rpc |
service | The service associated with the gRPC method of the ServerRPC |
rpc_handler | A callable that produces a coroutine. The coroutine's return value is ignored. |
token | A completion token for signature void(std::exception_ptr) . |
auto agrpc::register_coroutine_rpc_handler | ( | agrpc::GrpcContext & | grpc_context, |
detail::ServerRPCServiceT< ServerRPC > & | service, | ||
RPCHandler && | rpc_handler, | ||
CompletionToken && | token ) |
(experimental) Register an coroutine rpc handler for the given method (GrpcContext overload)
|
nodiscard |
Register a sender rpc handler for the given method.
The rpc handler will be invoked for every incoming request of this gRPC method. It must take ServerRPC&
as first argument and ServerRPC::Request&
as second argument (only for unary and server-streaming rpcs). The ServerRPC is automatically cancelled at the end of the rpc handler's sender if finish()
was not called earlier.
This asynchronous operation runs forever unless it is cancelled, the rpc handler throws an exception or the server is shutdown (grpc::Server::Shutdown is called). At which point it invokes the receiver (passing forward the exception thrown by the request handler, if any) after all sender produced by invoking the rpc handler complete.
Example:
ServerRPC | An instantiation of agrpc::ServerRPC |
grpc_context | The GrpcContext used to handle each rpc |
service | The service associated with the gRPC method of the ServerRPC |
rpc_handler | A callable that produces a sender |
auto agrpc::register_yield_rpc_handler | ( | const typename ServerRPC::executor_type & | executor, |
detail::ServerRPCServiceT< ServerRPC > & | service, | ||
RPCHandler | rpc_handler, | ||
CompletionToken && | token = CompletionToken{} ) |
Register a Boost.Coroutine rpc handler for the given method.
The rpc handler will be invoked for every incoming request of this gRPC method. It must take ServerRPC&
as first, ServerRPC::Request&
as second (only for unary and server-streaming rpcs) and asio::basic_yield_context<Executor>
as third argument. The Executor is obtained by calling asio::get_associated_executor(completion_handler, executor)
, where completion_handler
is created from token
and executor
the first argument passed to this function. The ServerRPC is automatically cancelled at the end of the rpc handler if finish()
was not called earlier.
This asynchronous operation runs forever unless it is cancelled, the rpc handler throws an exception or the server is shutdown (grpc::Server::Shutdown is called). At which point it invokes the completion handler (passing forward the exception thrown by the request handler, if any) after all invocations of the rpc handler return.
Example:
ServerRPC | An instantiation of agrpc::ServerRPC |
executor | The executor used to handle each rpc |
service | The service associated with the gRPC method of the ServerRPC |
rpc_handler | A callable that takes an asio::basic_yield_context<Executor> as last argument. The return value is ignored. The Executor must be constructible from asio::get_associated_executor(completion_handler,
executor) , where completion_handler is obtained from token and executor the first argument passed to this function. |
token | A completion token for signature void(std::exception_ptr) . |
auto agrpc::register_yield_rpc_handler | ( | agrpc::GrpcContext & | grpc_context, |
detail::ServerRPCServiceT< ServerRPC > & | service, | ||
RPCHandler && | rpc_handler, | ||
CompletionToken && | token ) |
Register a rpc handler for the given method (GrpcContext overload)
void agrpc::run | ( | agrpc::GrpcContext & | grpc_context, |
ExecutionContext & | execution_context ) |
(experimental) Run an execution context in the same thread as a GrpcContext
The GrpcContext should be in the ready state when this function is invoked, other than that semantically identical to GrpcContext::run(). This function ends when the GrpcContext is stopped, e.g. because it ran out of work.
Traits | See DefaultRunTraits |
void agrpc::run | ( | agrpc::GrpcContext & | grpc_context, |
ExecutionContext & | execution_context, | ||
StopCondition | stop_condition ) |
(experimental) Run an execution context in the same thread as a GrpcContext
The GrpcContext should be in the ready state when this function is invoked, other than that semantically identical to GrpcContext::run(). This function ends when the stop_condition
returns true
.
Traits | See DefaultRunTraits |
void agrpc::run_completion_queue | ( | agrpc::GrpcContext & | grpc_context, |
ExecutionContext & | execution_context ) |
(experimental) Run an execution context in the same thread as a GrpcContext's completion queue
The GrpcContext should be in the ready state when this function is invoked, other than that semantically identical to GrpcContext::run_completion_queue(). This function ends when the GrpcContext is stopped, e.g. because it ran out of work.
Traits | See DefaultRunTraits |
void agrpc::run_completion_queue | ( | agrpc::GrpcContext & | grpc_context, |
ExecutionContext & | execution_context, | ||
StopCondition | stop_condition ) |
(experimental) Run an execution context in the same thread as a GrpcContext's completion queue
The GrpcContext should be in the ready state when this function is invoked, other than that semantically identical to GrpcContext::run_completion_queue(). This function ends when the stop_condition
returns true
.
Traits | See DefaultRunTraits |
|
inline |
Test utility to manually process gRPC tags.
This function can be used to process gRPC tags in places where the tag does not go through the grpc::CompletionQueue
, for example in mocked stubs. It processes the tag in a manner equivalent to asio::post
while being compatible with GrpcContext::run_completion_queue()
/GrpcContext::poll_completion_queue()
.
Example using Google Mock:
|
inlineconstexpr |
Set notification for a grpc::Channel
state change.
Function to set notification for a grpc::Channel
state change.
|
inlineconstexpr |
Read from a streaming RPC.
Client and server-side function to read from streaming RPCs.
|
inlineconstexpr |
Instance and factory for sender completion tokens.