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::ReadFuture< Message > Class Template Reference
Loading...
Searching...
No Matches
pw::rpc2::ReadFuture< Message > Class Template Reference

Overview

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

Future that resolves to the next inbound message of a stream (RpcResult<Message>). Returned by Reader::Read().

At most one ReadFuture may be active on a call at a time: starting a second read while an earlier ReadFuture is still pending fails with an assertion rather than silently splitting the incoming message stream. As soon as Pend() resolves, the read claim is released so the next read can be started even if the completed ReadFuture remains in scope.

A ReadFuture holds a shared reference to the underlying call, so it stays valid even if the Reader that produced it is destroyed first.

Inheritance diagram for pw::rpc2::ReadFuture< Message >:
pw::rpc2::internal::ReadFutureBase pw::rpc2::internal::FutureBase

Public Types

using value_type = RpcResult< Message >
 

Public Member Functions

 ReadFuture (const ReadFuture &)=delete
 
ReadFuture & operator= (const ReadFuture &)=delete
 
 ReadFuture (ReadFuture &&) noexcept=default
 
ReadFuture & operator= (ReadFuture &&) noexcept=default
 
async2::Poll< RpcResult< Message > > Pend (async2::Context &cx)
 
- Public Member Functions inherited from pw::rpc2::internal::ReadFutureBase
 ReadFutureBase (const ReadFutureBase &)=delete
 
ReadFutureBase & operator= (const ReadFutureBase &)=delete
 
- Public Member Functions inherited from pw::rpc2::internal::FutureBase
 FutureBase (const FutureBase &)=delete
 
FutureBase & operator= (const FutureBase &)=delete
 
constexpr bool is_pendable () const
 
constexpr bool is_complete () const
 

Friends

class Reader< Message >
 
struct internal::CallAccess
 

Additional Inherited Members

- Protected Member Functions inherited from pw::rpc2::internal::ReadFutureBase
 ReadFutureBase (const IntrusivePtr< Call > &call)
 
 ReadFutureBase (IntrusivePtr< Call > &&call)
 
 ReadFutureBase (ReadFutureBase &&other) noexcept=default
 
ReadFutureBase & operator= (ReadFutureBase &&other) noexcept
 
async2::Poll< RpcResult< ConstBuf > > PendRaw (async2::Context &cx)
 
void PendAndDeserialize (async2::Context &cx, void *result_out, DeserializeFn deserialize)
 
- Protected Member Functions inherited from pw::rpc2::internal::FutureBase
constexpr FutureBase (async2::FutureState::Pending)
 
constexpr FutureBase (async2::FutureState state)
 
constexpr FutureBase (FutureBase &&) noexcept=default
 
constexpr FutureBase & operator= (FutureBase &&) noexcept=default
 
constexpr void mark_pending ()
 
void mark_complete ()
 

Member Function Documentation

◆ Pend()

template<typename Message = ConstBuf>
async2::Poll< RpcResult< Message > > pw::rpc2::ReadFuture< Message >::Pend ( async2::Context &  cx)
inline

Polls for the inbound message.

Returns
  • kOk with the decoded Message (or raw ConstBuf) when a message arrives.
  • kEndOfStream when the peer has finished its outbound stream (Finish() or ~Writer()) and all sent messages have been read. This is the normal end-of-stream condition for a Reader loop, not an error.
  • kDataError if a message could not be decoded. If the incoming bytes could not be decoded as Message, only that message is dropped: the stream stays open, and the next read may succeed. If the server could not decode the request, the call is over, and every later read returns kDataError too.
  • The status that ended the call, if it ended with an error: for example, kCancelled if either end cancelled the RPC; kClosed, kDisconnected, or kProtocolError if the connection closed; or kUnimplemented, kUnavailable, kAborted, or kProtocolError if the peer ended the call. See Error handling.

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