Your opinion will help to improve our service
Leave a feedback >#include <userver/ugrpc/client/rpc.hpp>
Controls a request stream -> response stream RPC.
It is safe to call the following methods from different coroutines:
GetContext
;Read
, ReadAsync
);Write
, WritesDone
).WriteAndCheck
is NOT thread-safe.
The RPC is cancelled on destruction unless the stream is closed (Read
has returned false
). In that case the connection is not closed (it will be reused for new RPCs), and the server receives RpcInterruptedError
immediately. gRPC provides no way to early-close a server-streaming RPC gracefully.
Read
and AsyncRead
can throw if error status is received from server. User MUST NOT call Read
or AsyncRead
again after failure of any of these operations.
Write
and WritesDone
methods do not throw, but indicate issues with the RPC by returning false
.
WriteAndCheck
is intended for ping-pong scenarios, when after write operation the user calls Read
and vice versa.
If Write
or WritesDone
returns negative result, the user MUST NOT call any of these methods anymore. Instead the user SHOULD call Read
method until the end of input. If Write
or WritesDone
finishes with negative result, finally Read
will throw an exception.
Public Member Functions | |
bool | Read (Response &response) |
Await and read the next incoming message. | |
StreamReadFuture< BidirectionalStream > | ReadAsync (Response &response) |
Return future to read next incoming result. | |
bool | Write (const Request &request) |
Write the next outgoing message. | |
void | WriteAndCheck (const Request &request) |
Write the next outgoing message and check result. | |
bool | WritesDone () |
Announce end-of-output to the server. | |
BidirectionalStream (BidirectionalStream &&) noexcept=default | |
BidirectionalStream & | operator= (BidirectionalStream &&) noexcept=default |
grpc::ClientContext & | GetContext () |
std::string_view | GetClientName () const |
std::string_view | GetCallName () const |
tracing::Span & | GetSpan () |
|
defaultnoexcept |
|
inherited |
|
inherited |
|
inherited |
ClientContext
used for this RPC
|
inherited |
|
nodiscard |
Await and read the next incoming message.
On end-of-input, Finish
is called automatically.
response | where to put response on success |
true
on success, false
on end-of-input, task cancellation, or if the stream is already closed for reads ugrpc::client::RpcError | on an RPC error |
StreamReadFuture< BidirectionalStream< Request, Response > > ugrpc::client::BidirectionalStream< Request, Response >::ReadAsync | ( | Response & | response | ) |
Return future to read next incoming result.
response | where to put response on success |
ugrpc::client::RpcError | on an RPC error |
ugrpc::client::RpcError | if the stream is already closed for reads |
|
nodiscard |
Write the next outgoing message.
RPC will be performed immediately. No references to request
are saved, so it can be deallocated right after the call.
request | the next message to write |
void ugrpc::client::BidirectionalStream< Request, Response >::WriteAndCheck | ( | const Request & | request | ) |
Write the next outgoing message and check result.
WriteAndCheck
doesn't store any references to request
, so it can be deallocated right after the call.
WriteAndCheck
verifies result of the write and generates exception in case of issues.
request | the next message to write |
ugrpc::client::RpcError | on an RPC error |
ugrpc::client::RpcCancelledError | on task cancellation |
ugrpc::client::RpcError | if the stream is already closed for writes |
|
nodiscard |
Announce end-of-output to the server.
Should be called to notify the server and receive the final response(s).