#include <userver/ugrpc/client/stream.hpp>
Client-side interface for bi-directional streaming.
It is safe to call the following methods from different coroutines:
GetContext
;Read
, ReadAsync
);Write
, WritesDone
).WriteAndCheck
is NOT thread-safe.
The RPC should be completed by reading until ugrpc::client::Reader::Read returns false
. If destroyed early, the RPC is cancelled. The server gets ugrpc::client::RpcInterruptedError and the abandoned-error
metric is incremented. The connection stays open for reuse. 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.
Definition at line 170 of file stream.hpp.
Public Types | |
using | StreamReadFuture = ugrpc::client::StreamReadFuture< typename impl::BidirectionalStream< Request, Response >::RawStream > |
Public Member Functions | |
ReaderWriter (ReaderWriter &&) noexcept=default | |
ReaderWriter & | operator= (ReaderWriter &&) noexcept=default |
bool | Read (Response &response) |
Await and read the next incoming message. | |
StreamReadFuture | 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. | |
CallContext & | GetContext () |
Get call context, useful e.g. for accessing metadata. | |
const CallContext & | GetContext () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
using ugrpc::client::ReaderWriter< Request, Response >::StreamReadFuture = ugrpc::client::StreamReadFuture<typename impl::BidirectionalStream<Request, Response>::RawStream> |
Definition at line 172 of file stream.hpp.
|
inline |
Get call context, useful e.g. for accessing metadata.
Definition at line 246 of file stream.hpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 248 of file stream.hpp.
|
inline |
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 |
Definition at line 199 of file stream.hpp.
|
inline |
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 |
Definition at line 207 of file stream.hpp.
|
inline |
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 |
Definition at line 220 of file stream.hpp.
|
inline |
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 |
Definition at line 234 of file stream.hpp.
|
inline |
Announce end-of-output to the server.
Should be called to notify the server and receive the final response(s).
Definition at line 243 of file stream.hpp.