asio-grpc v3.1.0
Asynchronous gRPC with Asio/unified executors
|
I/O object for server-side, client-streaming rpcs. More...
#include <agrpc/server_rpc.hpp>
Classes | |
struct | rebind_executor |
Rebind the ServerRPC to another executor. More... | |
Public Types | |
using | Request = RequestT |
The response message type. | |
using | Response = ResponseT |
The request message type. | |
using | Traits = TraitsT |
The traits type. | |
using | Ptr = agrpc::ServerRPCPtr< ServerRPC > |
ServerRPCPtr specialized on this type. | |
using | executor_type = Executor |
The executor type. | |
Public Member Functions | |
ServerRPC ()=delete | |
Deleted default constructor. | |
template<class CompletionToken = detail::DefaultCompletionTokenT<Executor>> | |
auto | read (RequestT &req, CompletionToken &&token=detail::DefaultCompletionTokenT< Executor >{}) |
Receive a message from the client. More... | |
template<class CompletionToken = detail::DefaultCompletionTokenT<Executor>> | |
auto | finish (const ResponseT &response, const grpc::Status &status, CompletionToken &&token=detail::DefaultCompletionTokenT< Executor >{}) |
Finish the rpc. More... | |
template<class CompletionToken = detail::DefaultCompletionTokenT<Executor>> | |
auto | finish_with_error (const grpc::Status &status, CompletionToken &&token=detail::DefaultCompletionTokenT< Executor >{}) |
Finish the rpc with an error. More... | |
auto | send_initial_metadata (CompletionToken &&token=detail::DefaultCompletionTokenT< Executor >{}) |
Send initial metadata. More... | |
bool | is_done () const noexcept |
Is this rpc done? More... | |
auto | wait_for_done (CompletionToken &&token=detail::DefaultCompletionTokenT< Executor >{}) |
Wait for done. More... | |
const executor_type & | get_executor () const noexcept |
Get the executor. More... | |
const executor_type & | get_scheduler () const noexcept |
Get the scheduler. More... | |
auto & | context () |
Get the underlying ServerContext | |
const auto & | context () const |
Get the underlying ServerContext (const overload) | |
void | cancel () noexcept |
Cancel this RPC. More... | |
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::CLIENT_STREAMING |
The rpc type. | |
I/O object for server-side, client-streaming rpcs.
Use one of the agrpc::register_
functions to set up request handling.
Example:
Based on .proto
file:
RequestUnary | A pointer to the generated gRPC method. |
Traits | A type used to customize this rpc. See agrpc::DefaultServerRPCTraits . |
Executor | The 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.
|
inlinestaticconstexprnoexcept |
Name of the gRPC service.
Equal to the generated Service::service_full_name()
.
E.g. for the .proto
schema
the return value would be "example.v1.Example"
.
|
inlinestaticconstexprnoexcept |
Name of the gRPC method.
E.g. for agrpc::ServerRPC<&example::Example::AsyncService::RequestMyMethod>
the return value would be "MyMethod"
.
|
inline |
Receive a message from the client.
May not be called currently with finish
/finish_with_error
. It is not meaningful to call it concurrently with another read on the same rpc since reads on the same stream are delivered in order.
token | A completion token like asio::yield_context or agrpc::use_sender . The completion signature is void(bool) . true indicates that a valid message was read. false when there will be no more incoming messages, either because the other side has called WritesDone() or the stream has failed (or been cancelled). |
|
inline |
Finish the rpc.
Indicate that the stream is to be finished with a certain status code and also send out a response to the client.
Should not be used concurrently with other operations and may only be called once.
It is appropriate to call this method when:
false
).This operation will end when the server has finished sending out initial and trailing metadata, response message, and status, or if some failure occurred when trying to do so.
GRPC does not take ownership or a reference to response
or status
, so it is safe to deallocate once finish returns, unless a deferred completion token like agrpc::use_sender
or asio::deferred
is used.
token | A completion token like asio::yield_context or agrpc::use_sender . The completion signature is void(bool) . true means that the data/metadata/status/etc is going to go to the wire. If it is false , it is not going to the wire because the call is already dead (i.e., canceled, deadline expired, other side dropped the channel, etc). |
|
inline |
Finish the rpc with an error.
Indicate that the stream is to be finished with a certain non-OK status code.
Should not be used concurrently with other operations and may only be called once.
This call is meant to end the call with some error, and can be called at any point that the server would like to "fail" the call (except during send_initial_metadata
).
This operation will end when the server has finished sending out initial and trailing metadata and status, or if some failure occurred when trying to do so.
GRPC does not take ownership or a reference to status
, so it is safe to to deallocate once finish_with_error returns, unless a deferred completion token like agrpc::use_sender
or asio::deferred
is used.
token | A completion token like asio::yield_context or agrpc::use_sender . The completion signature is void(bool) . true means that the data/metadata/status/etc is going to go to the wire. If it is false , it is not going to the wire because the call is already dead (i.e., canceled, deadline expired, other side dropped the channel, etc). |
|
inlineinherited |
Send initial metadata.
Request notification of the sending of initial metadata to the client.
This call is optional, but if it is used, it cannot be used concurrently with or after the finish
/finish_with_error
method.
token | A completion token like asio::yield_context or agrpc::use_sender . The completion signature is void(bool) . true means that the data/metadata/status/etc is going to go to the wire. If it is false , it is not going to the wire because the call is already dead (i.e., canceled, deadline expired, other side dropped the channel, etc). |
|
inlinenoexceptinherited |
Is this rpc done?
Only available if Traits
contain NOTIFY_WHEN_DONE = true
.
Returns true if NotifyWhenDone has fired which indicates the finish
has been called or that the rpc is dead (i.e., canceled, deadline expired, other side dropped the channel, etc).
Thread-safe
|
inlineinherited |
Wait for done.
Only available if Traits
contain NOTIFY_WHEN_DONE = true
.
Request notification of the completion of this rpc, either due to calling finish
or because the rpc is dead (i.e., canceled, deadline expired, other side dropped the channel, etc). rpc.context().IsCancelled() may only be called after this operation completes.
Cancelling this operation does not invoke grpc::ServerContext::TryCancel.
token | A completion token like asio::yield_context or agrpc::use_sender . The completion signature is void() . |
|
inlinenoexceptinherited |
Get the executor.
Thread-safe
|
inlinenoexceptinherited |
Get the scheduler.
Thread-safe
|
inlinenoexceptinherited |