asio-grpc v3.3.0
Asynchronous gRPC with Asio/unified executors
|
Execution context based on grpc::CompletionQueue
More...
#include <agrpc/grpc_context.hpp>
Public Types | |
using | executor_type = agrpc::BasicGrpcExecutor<> |
The associated executor type. | |
using | allocator_type = detail::GrpcContextLocalAllocator |
The associated allocator type. | |
Public Member Functions | |
GrpcContext () | |
Construct a GrpcContext for gRPC clients. | |
GrpcContext (std::size_t concurrency_hint) | |
Construct a GrpcContext for multi-threaded gRPC clients. | |
GrpcContext (std::unique_ptr< grpc::ServerCompletionQueue > completion_queue) | |
Construct a GrpcContext for gRPC servers. | |
GrpcContext (std::unique_ptr< grpc::ServerCompletionQueue > completion_queue, std::size_t concurrency_hint) | |
Construct a GrpcContext for multi-threaded gRPC servers. | |
~GrpcContext () | |
Destruct the GrpcContext. | |
bool | run () |
Run ready completion handlers and grpc::CompletionQueue | |
template<class Deadline > | |
bool | run_until (const Deadline &deadline) |
Run ready completion handlers and grpc::CompletionQueue until deadline. | |
template<class Condition > | |
bool | run_while (Condition &&condition) |
Run ready completion handlers and grpc::CompletionQueue while a condition holds. | |
bool | run_completion_queue () |
Run the grpc::CompletionQueue | |
bool | poll () |
Poll ready completion handlers and grpc::CompletionQueue | |
bool | poll_completion_queue () |
Poll the grpc::CompletionQueue | |
void | stop () |
Signal the GrpcContext to stop. | |
void | reset () noexcept |
Bring a stopped GrpcContext back into the ready state. | |
bool | is_stopped () const noexcept |
Is the GrpcContext in the stopped state? | |
executor_type | get_executor () noexcept |
Get the associated executor. | |
executor_type | get_scheduler () noexcept |
Get the associated scheduler. | |
allocator_type | get_allocator () noexcept |
Get the associated allocator. | |
void | work_started () noexcept |
Signal that work has started. | |
void | work_finished () noexcept |
Signal that work has finished. | |
grpc::CompletionQueue * | get_completion_queue () noexcept |
Get the underlying grpc::CompletionQueue | |
grpc::ServerCompletionQueue * | get_server_completion_queue () noexcept |
Get the underlying grpc::CompletionQueue | |
Execution context based on grpc::CompletionQueue
Satisfies the ExecutionContext requirements and can therefore be used in all places where Asio expects an ExecutionContext
.
Performance recommendation: Use exactly one GrpcContext per thread.
|
inline |
Construct a GrpcContext for gRPC clients.
|
inlineexplicit |
Construct a GrpcContext for multi-threaded gRPC clients.
|
inlineexplicit |
Construct a GrpcContext for gRPC servers.
The resulting GrpcContext can also be used for clients.
Example:
|
inline |
Construct a GrpcContext for multi-threaded gRPC servers.
The resulting GrpcContext can also be used for clients.
Example:
|
inline |
Destruct the GrpcContext.
Calls Shutdown() on the grpc::CompletionQueue
and drains it. Pending completion handlers will not be invoked.
|
inline |
Run ready completion handlers and grpc::CompletionQueue
Runs the main event loop logic until the GrpcContext runs out of work or is stopped. The GrpcContext will be brought into the ready state when this function is invoked. Upon return, the GrpcContext will be in the stopped state.
concurrency_hint
greater than one. Even then it may not be called concurrently with run_completion_queue() or poll_completion_queue() (since 3.2.0)].
|
inline |
Run ready completion handlers and grpc::CompletionQueue
until deadline.
Runs the main event loop logic until the GrpcContext runs out of work, is stopped or the specified deadline has been reached. The GrpcContext will be brought into the ready state when this function is invoked.
concurrency_hint
greater than one. Even then it may not be called concurrently with run_completion_queue() or poll_completion_queue() (since 3.2.0)].Deadline | A type that is compatible with grpc::TimePoint<Deadline> . |
|
inline |
Run ready completion handlers and grpc::CompletionQueue
while a condition holds.
Runs the main event loop logic until the GrpcContext runs out of work, is stopped or the specified condition returns false. The GrpcContext will be brought into the ready state when this function is invoked.
concurrency_hint
greater than one. Even then it may not be called concurrently with run_completion_queue() or poll_completion_queue() (since 3.2.0)].Condition | A callable that returns false when the GrpcContext should stop. |
|
inline |
Run the grpc::CompletionQueue
Runs the main event loop logic until the GrpcContext runs out of work or is stopped. Only events from the grpc::CompletionQueue
will be handled. That means that completion handler that were e.g. created using asio::post(grpc_context, ...)
will not be processed. The GrpcContext will be brought into the ready state when this function is invoked. Upon return, the GrpcContext will be in the stopped state.
concurrency_hint
greater than one. Even then it may not be called concurrently with run, run_until, run_while and poll (since 3.2.0)].
|
inline |
Poll ready completion handlers and grpc::CompletionQueue
Processes all ready completion handlers and ready events of the grpc::CompletionQueue
. The GrpcContext will be brought into the ready state when this function is invoked.
concurrency_hint
greater than one. Even then it may not be called concurrently with run_completion_queue() or poll_completion_queue() (since 3.2.0)].
|
inline |
Poll the grpc::CompletionQueue
Processes only ready events of the grpc::CompletionQueue
. That means that completion handler that were e.g. created using asio::post(grpc_context, ...)
will not be processed. The GrpcContext will be brought into the ready state when this function is invoked.
concurrency_hint
greater than one. Even then it may not be called concurrently with run, run_until, run_while and poll (since 3.2.0)].
|
inline |
Signal the GrpcContext to stop.
Causes a call to run() to return as soon as possible.
Thread-safe with regards to other functions except the destructor.
|
inlinenoexcept |
Bring a stopped GrpcContext back into the ready state.
When a call to run() or stop() returns, the GrpcContext will be in a stopped state. This function brings the GrpcContext back into the ready state.
Thread-safe with regards to other functions except the destructor.
|
inlinenodiscardnoexcept |
Is the GrpcContext in the stopped state?
Thread-safe
|
inlinenodiscardnoexcept |
Get the associated executor.
Thread-safe
|
inlinenodiscardnoexcept |
Get the associated scheduler.
Thread-safe
|
inlinenodiscardnoexcept |
Get the associated allocator.
Thread-safe
|
inlinenoexcept |
Signal that work has started.
The GrpcContext maintains an internal counter on how many operations have been started. Once that counter reaches zero it will go into the stopped state. Every call to work_started() should be matched to a call of work_finished().
Thread-safe
|
inlinenoexcept |
Signal that work has finished.
Thread-safe
|
inlinenodiscardnoexcept |
Get the underlying grpc::CompletionQueue
Do not use any functions of the returned CompletionQueue that might interfere with the GrpcContext, like Next().
Do not delete the returned pointer.
Thread-safe, never nullptr
|
inlinenodiscardnoexcept |
Get the underlying grpc::CompletionQueue
Do not use any functions of the returned CompletionQueue that might interfere with the GrpcContext, like Next().
Do not delete the returned pointer.
Thread-safe, never nullptr