OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::rpc::tcp_client< Request, Response > Class Template Reference

Implements an RPC client over TCP sockets. More...

#include <tcp_client.hpp>

Inheritance diagram for cbdc::rpc::tcp_client< Request, Response >:
Collaboration diagram for cbdc::rpc::tcp_client< Request, Response >:

Public Types

using response_type
 
- Public Types inherited from cbdc::rpc::client< Request, Response >
using request_type = request<Request>
 
using response_type = response<Response>
 
using response_callback_type = std::function<void(std::optional<Response>)>
 User-provided response callback function type for asynchronous requests.
 

Public Member Functions

 tcp_client (std::vector< network::endpoint_t > server_endpoints)
 Constructor.
 
 tcp_client (tcp_client &&)=delete
 
auto operator= (tcp_client &&) -> tcp_client &=delete
 
 tcp_client (const tcp_client &)=delete
 
auto operator= (const tcp_client &) -> tcp_client &=delete
 
 ~tcp_client () override
 Destructor.
 
auto init (std::optional< bool > error_fatal=std::nullopt) -> bool
 Initializes the client.
 
- Public Member Functions inherited from cbdc::rpc::client< Request, Response >
 client ()=default
 
 client (client &&) noexcept=default
 
auto operator= (client &&) noexcept -> client &=default
 
 client (const client &)=delete
 
auto operator= (const client &) -> client &=delete
 
virtual ~client ()=default
 
auto call (Request request_payload, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero()) -> std::optional< Response >
 Issues the given request with an optional timeout, then waits for and returns the response.
 
auto call (Request request_payload, response_callback_type response_callback) -> bool
 Issues an asynchronous request and registers the given callback to handle the response.
 

Additional Inherited Members

- Protected Types inherited from cbdc::rpc::client< Request, Response >
using raw_callback_type = std::function<void(std::optional<response_type>)>
 Response callback function type for handling an RPC response.
 
- Protected Member Functions inherited from cbdc::rpc::client< Request, Response >
auto deserialize_response (cbdc::buffer &response_buf) -> std::optional< response_type >
 Deserializes a response object from the given buffer.
 

Detailed Description

template<typename Request, typename Response>
class cbdc::rpc::tcp_client< Request, Response >

Implements an RPC client over TCP sockets.

Accepts multiple server endpoints for failover purposes.

See also
cbdc::rpc::tcp_server
Template Parameters
Requesttype for requests.
Responsetype for responses.

Definition at line 23 of file tcp_client.hpp.

Member Typedef Documentation

◆ response_type

template<typename Request , typename Response >
using cbdc::rpc::tcp_client< Request, Response >::response_type
Initial value:

Definition at line 35 of file tcp_client.hpp.

Constructor & Destructor Documentation

◆ tcp_client() [1/3]

template<typename Request , typename Response >
cbdc::rpc::tcp_client< Request, Response >::tcp_client ( std::vector< network::endpoint_t > server_endpoints)
inlineexplicit

Constructor.

Parameters
server_endpointsRPC server endpoints to which to connect.

Definition at line 27 of file tcp_client.hpp.

◆ tcp_client() [2/3]

template<typename Request , typename Response >
cbdc::rpc::tcp_client< Request, Response >::tcp_client ( tcp_client< Request, Response > && )
delete

◆ tcp_client() [3/3]

template<typename Request , typename Response >
cbdc::rpc::tcp_client< Request, Response >::tcp_client ( const tcp_client< Request, Response > & )
delete

◆ ~tcp_client()

template<typename Request , typename Response >
cbdc::rpc::tcp_client< Request, Response >::~tcp_client ( )
inlineoverride

Destructor.

Disconnects from the RPC servers and stops the response handler thread.

Definition at line 40 of file tcp_client.hpp.

References cbdc::network::connection_manager::close().

Here is the call graph for this function:

Member Function Documentation

◆ init()

template<typename Request , typename Response >
auto cbdc::rpc::tcp_client< Request, Response >::init ( std::optional< bool > error_fatal = std::nullopt) -> bool
inlinenodiscard

Initializes the client.

Connects to the server endpoints and starts the response handler thread.

Parameters
error_fataltreat connection errors as fatal. If this is set to true, failure to connect to any of the endpoints will result in failure to start the client and return false from this function. If this is set to false, any connection error will be silently ignored and the handler thread will be started. The client will continue to retry connecting in the background. If this is std::nullopt, connection errors are only treated as fatal when there is a single endpoint.
Returns
false if there is a fatal connection error, true if the client is connected and ready and the response handler is started.

Definition at line 71 of file tcp_client.hpp.

References cbdc::network::connection_manager::cluster_connect(), and cbdc::network::connection_manager::start_handler().

Here is the call graph for this function:

◆ operator=() [1/2]

template<typename Request , typename Response >
auto cbdc::rpc::tcp_client< Request, Response >::operator= ( const tcp_client< Request, Response > & ) -> tcp_client &=delete
delete

◆ operator=() [2/2]

template<typename Request , typename Response >
auto cbdc::rpc::tcp_client< Request, Response >::operator= ( tcp_client< Request, Response > && ) -> tcp_client &=delete
delete

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