asio-grpc v1.6.0
Asynchronous gRPC with Asio/unified executors
|
Execution context based on grpc::CompletionQueue
More...
#include <agrpc/grpcContext.hpp>
Inherits boost::asio::execution_context.
Public Types | |
using | executor_type = agrpc::BasicGrpcExecutor<> |
The associated executor type. | |
using | allocator_type = detail::GrpcContextLocalAllocator |
The associated allocator type. | |
Public Member Functions | |
GrpcContext (std::unique_ptr< grpc::CompletionQueue > &&completion_queue) | |
Construct a GrpcContext from a grpc::CompletionQueue More... | |
~GrpcContext () | |
Destruct the GrpcContext. More... | |
bool | run () |
Run the grpc::CompletionQueue More... | |
bool | poll () |
Poll the grpc::CompletionQueue More... | |
void | stop () |
Signal the GrpcContext to stop. More... | |
void | reset () noexcept |
Bring a stopped GrpcContext back into the ready state. More... | |
bool | is_stopped () const noexcept |
Is the GrpcContext in the stopped state? More... | |
executor_type | get_executor () noexcept |
Get the associated executor. More... | |
executor_type | get_scheduler () noexcept |
Get the associated scheduler. More... | |
allocator_type | get_allocator () noexcept |
Get the associated allocator. More... | |
void | work_started () noexcept |
Signal that work has started. More... | |
void | work_finished () noexcept |
Signal that work has finished. More... | |
grpc::CompletionQueue * | get_completion_queue () noexcept |
Get the underlying grpc::CompletionQueue More... | |
grpc::ServerCompletionQueue * | get_server_completion_queue () noexcept |
Get the underlying grpc::CompletionQueue More... | |
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 one GrpcContext per thread.
|
inlineexplicit |
Construct a GrpcContext from a grpc::CompletionQueue
For servers and clients:
For clients only:
|
inline |
Destruct the GrpcContext.
Calls Shutdown() on the grpc::CompletionQueue
and drains it. Pending completion handlers will not be invoked.
|
inlinenoexcept |
Get the associated allocator.
Thread-safe
|
inlinenoexcept |
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
|
inlinenoexcept |
Get the associated executor.
Thread-safe
|
inlinenoexcept |
Get the associated scheduler.
Thread-safe
|
inlinenoexcept |
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
|
inlinenoexcept |
Is the GrpcContext in the stopped state?
Thread-safe
|
inline |
|
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.
|
inline |
Run the 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.
Thread-safe with regards to other functions except run(), poll() and the destructor.
|
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 |
Signal that work has finished.
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