asio-grpc v3.3.0
Asynchronous gRPC with Asio/unified executors
Loading...
Searching...
No Matches
agrpc Namespace Reference

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.
 

Detailed Description

Public namespace.

Typedef Documentation

◆ Alarm

◆ GenericUnaryClientRPC

I/O object for client-side, generic, unary rpcs (type alias)

See also
agrpc::ClientRPC<agrpc::ClientRPCType::GENERIC_UNARY,Executor>
Since
2.6.0

◆ GenericStreamingClientRPC

◆ GrpcExecutor

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>).

◆ GenericServerRPC

Enumeration Type Documentation

◆ ClientRPCType

enum class agrpc::ClientRPCType
strong

The type of a ClientRPC.

Since
2.1.0
Enumerator
UNARY 

Client-side unary rpc.

GENERIC_UNARY 

Client-side generic unary rpc.

SERVER_STREAMING 

Client-side server-streaming rpc.

CLIENT_STREAMING 

Client-side client-streaming rpc.

BIDIRECTIONAL_STREAMING 

Client-side bidirectional-streaming rpc.

GENERIC_STREAMING 

Client-side generic streaming rpc.

◆ ServerRPCType

enum class agrpc::ServerRPCType
strong

The type of a ServerRPC.

Since
2.7.0
Enumerator
UNARY 

Server-side unary rpc.

SERVER_STREAMING 

Server-side server-streaming rpc.

CLIENT_STREAMING 

Server-side client-streaming rpc.

BIDIRECTIONAL_STREAMING 

Server-side bidirectional-streaming rpc.

GENERIC 

Server-side generic streaming rpc.

Function Documentation

◆ register_awaitable_rpc_handler() [1/2]

template<class ServerRPC , class RPCHandler , class CompletionToken = detail::DefaultCompletionTokenT<typename ServerRPC::executor_type>>
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_spawned 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:

void server_rpc_unary(agrpc::GrpcContext& grpc_context,
example::v1::Example::AsyncService& service)
{
using RPC = asio::use_awaitable_t<>::as_default_on_t<
grpc_context, service,
[](RPC& rpc, RPC::Request& request) -> asio::awaitable<void>
{
RPC::Response response;
response.set_integer(request.integer());
co_await rpc.finish(response, grpc::Status::OK);
// Alternatively finish with an error:
co_await rpc.finish_with_error(grpc::Status::CANCELLED);
},
asio::detached);
}
Template Parameters
ServerRPCAn instantiation of agrpc::ServerRPC
Parameters
executorThe executor used to handle each rpc
serviceThe service associated with the gRPC method of the ServerRPC
rpc_handlerA 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.
tokenA completion token for signature void(std::exception_ptr).
Since
2.7.0

◆ register_awaitable_rpc_handler() [2/2]

template<class ServerRPC , class RPCHandler , class CompletionToken >
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)

Since
2.7.0

◆ register_callback_rpc_handler() [1/2]

template<class ServerRPC , class RPCHandler , class CompletionToken = detail::DefaultCompletionTokenT<typename ServerRPC::executor_type>>
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::Ptrs have been destructed.

Example:

void server_rpc_unary_callback(agrpc::GrpcContext& grpc_context, example::v1::Example::AsyncService& service)
{
grpc_context, service,
[](RPC::Ptr ptr, RPC::Request& request)
{
RPC::Response response;
response.set_integer(request.integer());
auto& rpc = *ptr;
rpc.finish(response, grpc::Status::OK, [p = std::move(ptr)](bool) {});
},
asio::detached);
}
Template Parameters
ServerRPCAn instantiation of agrpc::ServerRPC
Parameters
executorThe executor used to handle each rpc
serviceThe service associated with the gRPC method of the ServerRPC
rpc_handlerA callable that handles the client's request
tokenA completion token for signature void(std::exception_ptr).
Since
2.8.0

◆ register_callback_rpc_handler() [2/2]

template<class ServerRPC , class RPCHandler , class CompletionToken >
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)

Since
2.8.0

◆ register_coroutine_rpc_handler() [1/2]

template<class ServerRPC , class CoroutineTraits , class RPCHandler , class CompletionToken = detail::DefaultCompletionTokenT<typename ServerRPC::executor_type>>
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_spawned 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.

Template Parameters
ServerRPCAn instantiation of agrpc::ServerRPC
CoroutineTraitsA class that provides functions for spawning the coroutine of each rpc. Example:
template <class Executor = boost::asio::any_io_executor, class Allocator = std::allocator<void>>
struct AsioCoroTraits
{
using ReturnType = boost::asio::experimental::coro<void, void, Executor, Allocator>;
template <class RPCHandler, class CompletionHandler>
static boost::asio::deferred_t completion_token(RPCHandler&, CompletionHandler&)
{
return {};
}
template <class RPCHandler, class CompletionHandler, class IoExecutor, class Function>
static void co_spawn(const IoExecutor& io_executor, RPCHandler&, CompletionHandler& completion_handler,
Function&& function)
{
boost::asio::experimental::co_spawn(
static_cast<Function&&>(function)(boost::asio::get_associated_executor(completion_handler, io_executor)),
boost::asio::detached);
}
};
Parameters
executorThe executor used to handle each rpc
serviceThe service associated with the gRPC method of the ServerRPC
rpc_handlerA callable that produces a coroutine. The coroutine's return value is ignored.
tokenA completion token for signature void(std::exception_ptr).
Since
3.3.0

◆ register_coroutine_rpc_handler() [2/2]

template<class ServerRPC , class CoroutineTraits , class RPCHandler , class CompletionToken >
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)

Since
3.3.0

◆ register_sender_rpc_handler()

template<class ServerRPC , class RPCHandler >
detail::RPCHandlerSender< ServerRPC, RPCHandler > agrpc::register_sender_rpc_handler ( agrpc::GrpcContext & grpc_context,
detail::ServerRPCServiceT< ServerRPC > & service,
RPCHandler rpc_handler )
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:

auto server_rpc_unary_sender(agrpc::GrpcContext& grpc_context, example::v1::Example::AsyncService& service)
{
return agrpc::register_sender_rpc_handler<RPC>(grpc_context, service,
[](RPC& rpc, RPC::Request& request)
{
return unifex::let_value_with(
[]
{
return RPC::Response{};
},
[&](auto& response)
{
response.set_integer(request.integer());
return rpc.finish(response, grpc::Status::OK);
});
});
}
Template Parameters
ServerRPCAn instantiation of agrpc::ServerRPC
Parameters
grpc_contextThe GrpcContext used to handle each rpc
serviceThe service associated with the gRPC method of the ServerRPC
rpc_handlerA callable that produces a sender
Since
2.7.0

◆ register_yield_rpc_handler() [1/2]

template<class ServerRPC , class RPCHandler , class CompletionToken = detail::DefaultCompletionTokenT<typename ServerRPC::executor_type>>
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:

void server_rpc_unary_yield(agrpc::GrpcContext& grpc_context, example::v1::Example::AsyncService& service)
{
grpc_context, service,
[](RPC& rpc, RPC::Request& request, const asio::yield_context& yield)
{
RPC::Response response;
response.set_integer(request.integer());
rpc.finish(response, grpc::Status::OK, yield);
},
asio::detached);
}
Template Parameters
ServerRPCAn instantiation of agrpc::ServerRPC
Parameters
executorThe executor used to handle each rpc
serviceThe service associated with the gRPC method of the ServerRPC
rpc_handlerA 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.
tokenA completion token for signature void(std::exception_ptr).
Since
2.7.0

◆ register_yield_rpc_handler() [2/2]

template<class ServerRPC , class RPCHandler , class CompletionToken >
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)

Since
2.7.0

◆ run() [1/2]

template<class Traits = agrpc::DefaultRunTraits, class ExecutionContext = void>
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.

Template Parameters
TraitsSee DefaultRunTraits
Since
1.7.0

◆ run() [2/2]

template<class Traits = agrpc::DefaultRunTraits, class ExecutionContext = void, class StopCondition = void>
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.

Template Parameters
TraitsSee DefaultRunTraits
Since
1.7.0

◆ run_completion_queue() [1/2]

template<class Traits = agrpc::DefaultRunTraits, class ExecutionContext = void>
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.

Template Parameters
TraitsSee DefaultRunTraits
Since
2.0.0

◆ run_completion_queue() [2/2]

template<class Traits = agrpc::DefaultRunTraits, class ExecutionContext = void, class StopCondition = void>
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.

Template Parameters
TraitsSee DefaultRunTraits
Since
2.0.0

◆ process_grpc_tag()

void agrpc::process_grpc_tag ( agrpc::GrpcContext & grpc_context,
void * tag,
bool ok )
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:

// Setup mock stub
struct MockResponseReader : grpc::ClientAsyncResponseReaderInterface<example::v1::Response>
{
MOCK_METHOD0(StartCall, void());
MOCK_METHOD1(ReadInitialMetadata, void(void*));
MOCK_METHOD3(Finish, void(example::v1::Response*, grpc::Status*, void*));
};
testing::NiceMock<example::v1::MockExampleStub> mock_stub;
testing::NiceMock<MockResponseReader> mock_reader;
EXPECT_CALL(mock_reader, Finish)
.WillOnce(
[&](example::v1::Response* response, grpc::Status* status, void* tag)
{
*status = grpc::Status::OK;
response->set_integer(42);
agrpc::process_grpc_tag(grpc_context, tag, true);
});
EXPECT_CALL(mock_stub, AsyncUnaryRaw).WillOnce(testing::Return(&mock_reader));
// Inject mock_stub into code under test
grpc::ClientContext client_context;
example::v1::Response response;
example::v1::Request request;
const grpc::Status status =
co_await RPC::request(grpc_context, mock_stub, client_context, request, response, asio::use_awaitable);
EXPECT_TRUE(status.ok());
EXPECT_EQ(42, response.integer());
Since
1.7.0

Variable Documentation

◆ notify_on_state_change

detail::NotifyOnStateChangeFn agrpc::notify_on_state_change {}
inlineconstexpr

Set notification for a grpc::Channel state change.

Function to set notification for a grpc::Channel state change.

Since
2.3.0

◆ read

detail::ReadFn agrpc::read {}
inlineconstexpr

◆ use_sender

agrpc::UseSender agrpc::use_sender {}
inlineconstexpr

Instance and factory for sender completion tokens.

Sender completion token.