Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. pw::rpc2::internal::WriterBase Class Reference
Loading...
Searching...
No Matches
pw::rpc2::internal::WriterBase Class Reference

Overview

Non-templated base class for outbound RPC handles (Writer and UnaryWriter).

Keeping WriterBase non-templated ensures that is_closed(), Cancel(), move-assignment, destruction, and packet reservation helpers are compiled once and shared across all writer types.

Inheritance diagram for pw::rpc2::internal::WriterBase:
pw::rpc2::Writer< ConstBuf > pw::rpc2::UnaryWriter< Message > pw::rpc2::Writer< Message >

Public Member Functions

 WriterBase (const WriterBase &)=delete
 
WriterBase & operator= (const WriterBase &)=delete
 
bool is_closed () const
 
void Cancel ()
 

Protected Types

enum  OnDestroy : bool { kFinishOnDestroy = false , kErrorOnDestroy = true }
 

Protected Member Functions

 WriterBase (const IntrusivePtr< Call > &call, OnDestroy on_destroy)
 
 WriterBase (IntrusivePtr< Call > &&call, OnDestroy on_destroy)
 
 WriterBase (WriterBase &&) noexcept=default
 
WriterBase & operator= (WriterBase &&other) noexcept
 
size_t payload_limit () const
 
ReserveWriteFuture ReserveMessage (size_t max_message_size) const
 
ReserveWriteFuture ReserveStreamEnd () const
 
ReserveWriteFuture ReserveResponse (size_t max_message_size) const
 

Member Enumeration Documentation

◆ OnDestroy

What destroying a writer before it is finished does to the call.

Writer ends its stream normally, since a stream may legitimately be empty. UnaryWriter ends the call with an error (ProtocolError::kDroppedWithoutResponse), since the peer is owed exactly one response.

Member Function Documentation

◆ Cancel()

void pw::rpc2::internal::WriterBase::Cancel ( )
inline

Aborts the call immediately, closing this writer and sending kCancelled to the peer.

Unlike Finish(), which indicates normal completion of the stream or RPC, Cancel() terminates the RPC in both directions. The peer's pending or next read fails with kCancelled, and so does this end's: the call completes locally with kCancelled, so a client's Reader or response future resolves instead of waiting for a server that will not answer. A write still in flight is rejected rather than sent.

◆ is_closed()

bool pw::rpc2::internal::WriterBase::is_closed ( ) const
inline

Returns true if no further writes can be initiated through this writer.

This becomes true once Finish() (or ReserveFinish()) is called, Cancel() is called, the peer cancels or finishes the call, or the connection closes. Server handlers can check is_closed() between async steps to stop work early if the client has disconnected or cancelled.

◆ payload_limit()

size_t pw::rpc2::internal::WriterBase::payload_limit ( ) const
inlineprotected

The largest payload a message or response packet on this call can carry, or 0 if the call cannot write.


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