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

Overview

Shared handle to an established RPC connection.

A Client refers to the connection it was created from: closing it closes the transport and cancels every call on it. Client is cheaply copyable, and all copies refer to the same underlying connection. Service clients wrap a Client and bind it to a service ID.

Note
Threading. Everything reachable through a client — its calls, their handles, and their futures — is bound to the dispatcher the client was created on and may only be used from that dispatcher's thread. Exceptions: Close(), CloseBlocking(), is_open(), and copying or destroying a Client are safe from any thread.
Closing. Destroying the last copy of a Client (including copies held by service clients) closes the connection and cancels its in-flight calls. The close happens asynchronously on the dispatcher. To be sure it has finished before destroying the dispatcher or allocator, call CloseBlocking() or await Close().

Public Member Functions

constexpr Client ()=default
 Constructs an empty client, which refers to no connection.
 
 Client (const Client &other)
 
Client & operator= (const Client &other)
 
 Client (Client &&other) noexcept=default
 
Client & operator= (Client &&other) noexcept
 
ControlFuture Close ()
 
void CloseBlocking ()
 
bool is_open () const
 

Static Public Member Functions

static ClientFuture Connect (async2::Dispatcher &dispatcher, Allocator &allocator, transport::ReliableDatagramConnector &connector)
 
static ClientFuture Connect (async2::Dispatcher &dispatcher, Allocator &allocator, transport::ReliableDatagramSocket connection)
 

Friends

class ClientFuture
 
class internal::GeneratedServiceClient
 
struct internal::CallAccess
 

Member Function Documentation

◆ Close()

ControlFuture pw::rpc2::Client::Close ( )

Closes the connection shared by this client and all its copies, completing every call on it with kClosed, and releases this client's handle to the connection. The returned future resolves to kOk once the dispatcher has torn the connection down, or immediately if the client is empty or already closed.

Call handles and futures still held by the user stay valid but inert until destroyed.

◆ CloseBlocking()

void pw::rpc2::Client::CloseBlocking ( )

Close(), but blocks the calling thread until the connection is closed.

Precondition
Must not be called from the client's own dispatcher thread.

◆ Connect() [1/2]

static ClientFuture pw::rpc2::Client::Connect ( async2::Dispatcher &  dispatcher,
Allocator &  allocator,
transport::ReliableDatagramConnector &  connector 
)
inlinestatic

Returns a future that connects to a peer through connector, performs the handshake, and resolves to the connected Client.

The client's connection task is allocated from allocator and runs on dispatcher.

◆ Connect() [2/2]

static ClientFuture pw::rpc2::Client::Connect ( async2::Dispatcher &  dispatcher,
Allocator &  allocator,
transport::ReliableDatagramSocket  connection 
)
inlinestatic

Returns a future that performs the handshake over an already-connected connection and resolves to the connected Client.

The client's connection task is allocated from allocator and runs on dispatcher.

◆ is_open()

bool pw::rpc2::Client::is_open ( ) const
inline

Returns true if this client refers to a connection that has not been closed.


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