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

Overview

Non-templated base class for outbound RPC handles (Writer and UnaryWriter), to share code across 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
 
size_t max_write_size_bytes () 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
 
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.

◆ max_write_size_bytes()

size_t pw::rpc2::internal::WriterBase::max_write_size_bytes ( ) const
inline

Returns the maximum size, in bytes, of a message that can be written through this writer. Returns 0 if is_closed().

0-length writes are valid, so do not rely on this function to determine whether the writer is closed; call is_closed() instead.


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