Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. pw_rpc2
  5. Readers and writers
  6. pw::rpc2::Reader< Message > Class Template Reference
Loading...
Searching...
No Matches
pw::rpc2::Reader< Message > Class Template Reference

Overview

template<typename Message = ConstBuf>
class pw::rpc2::Reader< Message >

Inbound message stream handle for reading a sequence of messages from the peer.

  • Server side (client-streaming and bidirectional-streaming RPCs): Reader<Request> reads the stream of requests sent by the client.
  • Client side (server-streaming and bidirectional-streaming RPCs): Reader<Response> reads the stream of responses sent by the server.

Call Read() in a loop until the returned ReadFuture resolves to kEndOfStream, which indicates that the peer called Finish() (or dropped its Writer) and no more messages will arrive.

Destroying a Reader before the stream ends stops reading incoming messages (any unread or subsequent messages from the peer are discarded).

  • Server side: it does not cancel the call or affect the outbound Writer or UnaryWriter.
  • Client side: if the RPC has not completed yet, it cancels the call, as Cancel() does, since nothing is left to observe its outcome. This keeps the server from running an abandoned RPC, such as an unbounded server stream, until the connection closes.
Inheritance diagram for pw::rpc2::Reader< Message >:
pw::rpc2::internal::ReaderBase

Public Member Functions

 Reader (const Reader &)=delete
 
Reader & operator= (const Reader &)=delete
 
 Reader (Reader &&) noexcept=default
 
Reader & operator= (Reader &&) noexcept=default
 
ReadFuture< Message > Read ()
 
- Public Member Functions inherited from pw::rpc2::internal::ReaderBase
 ReaderBase (const ReaderBase &)=delete
 
ReaderBase & operator= (const ReaderBase &)=delete
 
void Cancel ()
 

Friends

struct internal::CallAccess
 

Additional Inherited Members

- Protected Member Functions inherited from pw::rpc2::internal::ReaderBase
 ReaderBase (ReaderBase &&) noexcept=default
 
ReaderBase & operator= (ReaderBase &&other) noexcept
 

Member Function Documentation

◆ Read()

template<typename Message = ConstBuf>
ReadFuture< Message > pw::rpc2::Reader< Message >::Read ( )
inline

Returns a future that resolves to the next inbound message, or kEndOfStream once the peer has finished the stream.

Only one ReadFuture may be pending at a time; await or destroy the returned future before calling Read() again.


The documentation for this class was generated from the following file: