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

Client and server-side function object to write to streaming RPCs. More...

#include <agrpc/rpc.hpp>

Public Member Functions

template<class Response , class CompletionToken = agrpc::DefaultCompletionToken>
auto operator() (grpc::ServerAsyncWriter< Response > &writer, const Response &response, CompletionToken &&token={}) const noexcept(detail::IS_NOTRHOW_GRPC_INITIATE_COMPLETION_TOKEN< CompletionToken >)
 Write to a server stream. More...
 
template<class Response , class CompletionToken = agrpc::DefaultCompletionToken>
auto operator() (grpc::ServerAsyncWriter< Response > &writer, const Response &response, grpc::WriteOptions options, CompletionToken &&token={}) const noexcept(detail::IS_NOTRHOW_GRPC_INITIATE_COMPLETION_TOKEN< CompletionToken >)
 Write to a server stream. More...
 
template<class Response , class Request , class CompletionToken = agrpc::DefaultCompletionToken>
auto operator() (grpc::ServerAsyncReaderWriter< Response, Request > &reader_writer, const Response &response, CompletionToken &&token={}) const noexcept(detail::IS_NOTRHOW_GRPC_INITIATE_COMPLETION_TOKEN< CompletionToken >)
 Write to a bidirectional server stream. More...
 
template<class Response , class Request , class CompletionToken = agrpc::DefaultCompletionToken>
auto operator() (grpc::ServerAsyncReaderWriter< Response, Request > &reader_writer, const Response &response, grpc::WriteOptions options, CompletionToken &&token={}) const noexcept(detail::IS_NOTRHOW_GRPC_INITIATE_COMPLETION_TOKEN< CompletionToken >)
 Write to a bidirectional server stream. More...
 
template<class Request , class CompletionToken = agrpc::DefaultCompletionToken>
auto operator() (grpc::ClientAsyncWriter< Request > &writer, const Request &request, CompletionToken &&token={}) const noexcept(detail::IS_NOTRHOW_GRPC_INITIATE_COMPLETION_TOKEN< CompletionToken >)
 Write to a client stream. More...
 
template<class Request , class CompletionToken = agrpc::DefaultCompletionToken>
auto operator() (grpc::ClientAsyncWriter< Request > &writer, const Request &request, grpc::WriteOptions options, CompletionToken &&token={}) const noexcept(detail::IS_NOTRHOW_GRPC_INITIATE_COMPLETION_TOKEN< CompletionToken >)
 Write to a client stream. More...
 
template<class Request , class Response , class CompletionToken = agrpc::DefaultCompletionToken>
auto operator() (grpc::ClientAsyncReaderWriter< Request, Response > &reader_writer, const Request &request, CompletionToken &&token={}) const noexcept(detail::IS_NOTRHOW_GRPC_INITIATE_COMPLETION_TOKEN< CompletionToken >)
 Write to a bidirectional client stream. More...
 
template<class Request , class Response , class CompletionToken = agrpc::DefaultCompletionToken>
auto operator() (grpc::ClientAsyncReaderWriter< Request, Response > &reader_writer, const Request &request, grpc::WriteOptions options, CompletionToken &&token={}) const noexcept(detail::IS_NOTRHOW_GRPC_INITIATE_COMPLETION_TOKEN< CompletionToken >)
 Write to a bidirectional client stream. More...
 

Detailed Description

Client and server-side function object to write to streaming 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()() [1/8]

template<class Request , class Response , class CompletionToken = agrpc::DefaultCompletionToken>
auto agrpc::detail::WriteFn::operator() ( grpc::ClientAsyncReaderWriter< Request, Response > &  reader_writer,
const Request &  request,
CompletionToken &&  token = {} 
) const
inlinenoexcept

Write to a bidirectional client stream.

Only one write may be outstanding at any given time. This is thread-safe with respect to read. gRPC does not take ownership or a reference to request, so it is safe to to deallocate once write returns.

Example:

example::v1::Request request;
bool write_ok = co_await agrpc::write(*reader_writer, request, asio::use_awaitable);
constexpr detail::WriteFn write
Write to a streaming RPC.
Definition: rpc.hpp:1412
Parameters
tokenA completion token like asio::yield_context or the one created by 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).

◆ operator()() [2/8]

template<class Request , class Response , class CompletionToken = agrpc::DefaultCompletionToken>
auto agrpc::detail::WriteFn::operator() ( grpc::ClientAsyncReaderWriter< Request, Response > &  reader_writer,
const Request &  request,
grpc::WriteOptions  options,
CompletionToken &&  token = {} 
) const
inlinenoexcept

Write to a bidirectional client stream.

WriteOptions options is used to set the write options of this message, otherwise identical to: operator()(ClientAsyncReaderWriter&, const Request&, CompletionToken&&)

◆ operator()() [3/8]

template<class Request , class CompletionToken = agrpc::DefaultCompletionToken>
auto agrpc::detail::WriteFn::operator() ( grpc::ClientAsyncWriter< Request > &  writer,
const Request &  request,
CompletionToken &&  token = {} 
) const
inlinenoexcept

Write to a client stream.

Only one write may be outstanding at any given time. This is thread-safe with respect to read. gRPC does not take ownership or a reference to request, so it is safe to to deallocate once write returns.

Example:

example::v1::Request request;
bool write_ok = co_await agrpc::write(*writer, request, asio::use_awaitable);
Parameters
tokenA completion token like asio::yield_context or the one created by 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).

◆ operator()() [4/8]

template<class Request , class CompletionToken = agrpc::DefaultCompletionToken>
auto agrpc::detail::WriteFn::operator() ( grpc::ClientAsyncWriter< Request > &  writer,
const Request &  request,
grpc::WriteOptions  options,
CompletionToken &&  token = {} 
) const
inlinenoexcept

Write to a client stream.

WriteOptions options is used to set the write options of this message, otherwise identical to: operator()(ClientAsyncWriter&, const Request&, CompletionToken&&)

◆ operator()() [5/8]

template<class Response , class Request , class CompletionToken = agrpc::DefaultCompletionToken>
auto agrpc::detail::WriteFn::operator() ( grpc::ServerAsyncReaderWriter< Response, Request > &  reader_writer,
const Response &  response,
CompletionToken &&  token = {} 
) const
inlinenoexcept

Write to a bidirectional server stream.

Only one write may be outstanding at any given time. This is thread-safe with respect to read. gRPC does not take ownership or a reference to response, so it is safe to to deallocate once write returns.

Example:

bool write_ok = co_await agrpc::write(reader_writer, response, asio::use_awaitable);
Parameters
tokenA completion token like asio::yield_context or the one created by 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).

◆ operator()() [6/8]

template<class Response , class Request , class CompletionToken = agrpc::DefaultCompletionToken>
auto agrpc::detail::WriteFn::operator() ( grpc::ServerAsyncReaderWriter< Response, Request > &  reader_writer,
const Response &  response,
grpc::WriteOptions  options,
CompletionToken &&  token = {} 
) const
inlinenoexcept

Write to a bidirectional server stream.

WriteOptions options is used to set the write options of this message, otherwise identical to: operator()(ServerAsyncReaderWriter&, const Response&, CompletionToken&&)

◆ operator()() [7/8]

template<class Response , class CompletionToken = agrpc::DefaultCompletionToken>
auto agrpc::detail::WriteFn::operator() ( grpc::ServerAsyncWriter< Response > &  writer,
const Response &  response,
CompletionToken &&  token = {} 
) const
inlinenoexcept

Write to a server stream.

Only one write may be outstanding at any given time. This is thread-safe with respect to read. gRPC does not take ownership or a reference to response, so it is safe to to deallocate once write returns.

Example:

example::v1::Response response;
bool write_ok = co_await agrpc::write(writer, response, asio::use_awaitable);
Parameters
tokenA completion token like asio::yield_context or the one created by 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).

◆ operator()() [8/8]

template<class Response , class CompletionToken = agrpc::DefaultCompletionToken>
auto agrpc::detail::WriteFn::operator() ( grpc::ServerAsyncWriter< Response > &  writer,
const Response &  response,
grpc::WriteOptions  options,
CompletionToken &&  token = {} 
) const
inlinenoexcept

Write to a server stream.

WriteOptions options is used to set the write options of this message, otherwise identical to: operator()(ServerAsyncWriter&, const Response&, CompletionToken&&)