asio-grpc v1.4.0
Asynchronous gRPC with Asio/unified executors
agrpc::detail::ReadInitialMetadataFn Struct Reference

Client-side function object to read initial metadata for RPCs. More...

#include <agrpc/rpc.hpp>

Public Member Functions

template<class Responder , class CompletionToken = agrpc::DefaultCompletionToken>
auto operator() (Responder &responder, CompletionToken &&token={}) const noexcept(detail::IS_NOTRHOW_GRPC_INITIATE_COMPLETION_TOKEN< CompletionToken >)
 Read initial metadata. More...
 

Detailed Description

Client-side function object to read initial metadata for RPCs.

The examples below are based on the following .proto file:

syntax = "proto3";
package example.v1;
service Example {
rpc ServerStreaming(Request) returns (stream Response) {}
rpc ClientStreaming(stream Request) returns (Response) {}
rpc BidirectionalStreaming(stream Request) returns (stream Response) {}
rpc Unary(Request) returns (Response) {}
}
message Request {
int32 integer = 1;
}
message Response {
int32 integer = 1;
}
Attention
The completion handler created from the completion token that is provided to the functions described below must have an associated executor that refers to a GrpcContext:
asio::io_context io_context;
asio::co_spawn(
io_context,
[&]() -> asio::awaitable<void>
{
grpc::ServerContext server_context;
grpc::ServerAsyncReader<example::v1::Response, example::v1::Request> reader{&server_context};
// error: asio::this_coro::executor does not refer to a GrpcContext
// co_await agrpc::request(&example::v1::Example::AsyncService::RequestClientStreaming, service,
// server_context, reader, asio::use_awaitable);
// correct:
co_await agrpc::request(&example::v1::Example::AsyncService::RequestClientStreaming, service,
server_context, reader, asio::bind_executor(grpc_context, asio::use_awaitable));
},
asio::detached);
constexpr detail::RequestFn request
Start a new RPC.
Definition: rpc.hpp:1394

Member Function Documentation

◆ operator()()

template<class Responder , class CompletionToken = agrpc::DefaultCompletionToken>
auto agrpc::detail::ReadInitialMetadataFn::operator() ( Responder &  responder,
CompletionToken &&  token = {} 
) const
inlinenoexcept

Read initial metadata.

Request notification of the reading of the initial metadata.

This call is optional, but if it is used, it cannot be used concurrently with or after the read method.

Side effect:

  • Upon receiving initial metadata from the server, the ClientContext associated with this call is updated, and the calling code can access the received metadata through the ClientContext.

Example:

bool read_ok = co_await agrpc::read_initial_metadata(*reader, asio::use_awaitable);
constexpr detail::ReadInitialMetadataFn read_initial_metadata
Read initial metadata for a RPC.
Definition: rpc.hpp:1475
Parameters
respondergrpc::ClientAsyncResponseReader, grpc::ClientAsyncReader, grpc::ClientAsyncWriter or grpc::ClientAsyncReaderWriter
tokenA completion token like asio::yield_context or the one created by agrpc::use_sender. The completion signature is void(bool). true indicates that the metadata was read, false when the call is dead.