asio-grpc v3.4.3
Asynchronous gRPC with Asio/unified executors
Loading...
Searching...
No Matches
agrpc::BasicClientWriteReactor< Request, Executor > Class Template Reference

I/O object for client-side, client-streaming rpcs. More...

#include <agrpc/client_callback.hpp>

+ Inheritance diagram for agrpc::BasicClientWriteReactor< Request, Executor >:
+ Collaboration diagram for agrpc::BasicClientWriteReactor< Request, Executor >:

Classes

struct  rebind_executor
 Rebind the BasicClientWriteReactor to another executor. More...
 

Public Types

using executor_type = Executor
 The executor type.
 

Public Member Functions

template<class StubAsync , class Response >
void start (detail::AsyncClientStreamingReactorFn< StubAsync, Request, Response > fn, StubAsync *stub, Response &response)
 Start a codegen-ed rpc.
 
template<class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto wait_for_initial_metadata (CompletionToken &&token=CompletionToken{})
 Wait for initial metadata.
 
void initiate_write (const Request &request, grpc::WriteOptions options={})
 Write message.
 
void initiate_writes_done ()
 Indicate that the rpc will have no more write operations.
 
template<class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto wait_for_write (CompletionToken &&token=CompletionToken{})
 Wait for write.
 
template<class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto wait_for_writes_done (CompletionToken &&token=CompletionToken{})
 Wait for writes done.
 
template<class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto wait_for_finish (CompletionToken &&token=CompletionToken{})
 Wait for finish.
 
const Executor & get_executor () const noexcept
 Get the executor.
 
grpc::ClientContext & context () noexcept
 Get the underlying grpc::ClientContext
 
const grpc::ClientContext & context () const noexcept
 Get the underlying grpc::ClientContext (const overload)
 

Detailed Description

template<class Request, class Executor>
class agrpc::BasicClientWriteReactor< Request, Executor >

I/O object for client-side, client-streaming rpcs.

Create an object of this type using agrpc::make_reactor/agrpc::allocate_reactor.

Example:

void client_streaming(asio::io_context& io_context, example::v1::Example::Stub& stub)
{
auto& rpc = *ptr;
auto response = std::make_unique<example::v1::Response>();
rpc.start(&example::v1::Example::Stub::async::ClientStreaming, stub.async(), *response);
auto request = std::make_unique<example::v1::Request>();
rpc.initiate_write(*request);
rpc.wait_for_write(
[ptr = std::move(ptr), request = std::move(request), response = std::move(response)](const error_code&,
bool ok) mutable
{
if (!ok)
{
return;
}
ptr->wait_for_finish(
[response = std::move(response)](const error_code&, const grpc::Status& status)
{
if (!status.ok())
{
// ...
}
});
});
}

Based on .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;
}
Template Parameters
ExecutorThe executor type.

Per-Operation Cancellation

All. Cancellation will merely interrupt the act of waiting and does not cancel the underlying rpc.

Since
3.5.0

Member Function Documentation

◆ start()

template<class Request , class Executor >
template<class StubAsync , class Response >
void agrpc::BasicClientWriteReactor< Request, Executor >::start ( detail::AsyncClientStreamingReactorFn< StubAsync, Request, Response > fn,
StubAsync * stub,
Response & response )
inline

Start a codegen-ed rpc.

The response object must remain valid until the rpc is finished. May only be called once.

  • fn Pointer to the protoc generated Stub::async::Method.

◆ wait_for_initial_metadata()

template<class Request , class Executor >
template<class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto agrpc::BasicClientWriteReactor< Request, Executor >::wait_for_initial_metadata ( CompletionToken && token = CompletionToken{})
inline

Wait for initial metadata.

Only one wait for initial metadata may be outstanding at any time.

Completion signature is void(error_code, bool). If the bool is false then the rpc failed (cancelled, disconnected, deadline reached, ...).

◆ initiate_write()

template<class Request , class Executor >
void agrpc::BasicClientWriteReactor< Request, Executor >::initiate_write ( const Request & request,
grpc::WriteOptions options = {} )
inline

Write message.

Initiate the write of a message. The argument must remain valid until the write completes (wait_for_write). If WriteOptions::set_last_message() is present then no more calls to initiate_write or initiate_writes_done are allowed.

◆ initiate_writes_done()

template<class Request , class Executor >
void agrpc::BasicClientWriteReactor< Request, Executor >::initiate_writes_done ( )
inline

Indicate that the rpc will have no more write operations.

This can only be issued once for a given rpc. This is not required or allowed if initiate_write with set_last_message() is used since that already has the same implication. Note that calling this means that no more calls to initiate_write or initiate_writes_done are allowed.

◆ wait_for_write()

template<class Request , class Executor >
template<class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto agrpc::BasicClientWriteReactor< Request, Executor >::wait_for_write ( CompletionToken && token = CompletionToken{})
inline

Wait for write.

Waits for the completion of a write. Only one wait for write may be outstanding at any time.

Completion signature is void(error_code, bool). If the bool is false then the rpc failed (cancelled, disconnected, deadline reached, ...).

◆ wait_for_writes_done()

template<class Request , class Executor >
template<class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto agrpc::BasicClientWriteReactor< Request, Executor >::wait_for_writes_done ( CompletionToken && token = CompletionToken{})
inline

Wait for writes done.

Waits for the completion of writes_done. Only one wait for write may be outstanding at any time.

Completion signature is void(error_code, bool). If the bool is false then the rpc failed (cancelled, disconnected, deadline reached, ...).

◆ wait_for_finish()

template<class Request , class Executor >
template<class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto agrpc::BasicClientWriteReactor< Request, Executor >::wait_for_finish ( CompletionToken && token = CompletionToken{})
inline

Wait for finish.

Wait until all operations associated with this rpc have completed. No more writes may be initiated on this rpc after this function has been called. Only one wait for finish may be outstanding at any time.

Completion signature is void(error_code, grpc::Status). Once this operation completes the response passed to start() will have been be populated if grpc::Status::ok() is true.

◆ get_executor()

template<class Executor >
const Executor & agrpc::detail::ReactorExecutorBase< Executor >::get_executor ( ) const
inlinenodiscardnoexceptinherited

Get the executor.

Thread-safe