OpenCBDC Transaction Processor
|
Implements an RPC client over TCP sockets. More...
#include <tcp_client.hpp>
Public Types | |
using | response_type |
![]() | |
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. | |
![]() | |
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 | |
![]() | |
using | raw_callback_type = std::function<void(std::optional<response_type>)> |
Response callback function type for handling an RPC response. | |
![]() | |
auto | deserialize_response (cbdc::buffer &response_buf) -> std::optional< response_type > |
Deserializes a response object from the given buffer. | |
Implements an RPC client over TCP sockets.
Accepts multiple server endpoints for failover purposes.
Request | type for requests. |
Response | type for responses. |
Definition at line 23 of file tcp_client.hpp.
using cbdc::rpc::tcp_client< Request, Response >::response_type |
Definition at line 35 of file tcp_client.hpp.
|
inlineexplicit |
Constructor.
server_endpoints | RPC server endpoints to which to connect. |
Definition at line 27 of file tcp_client.hpp.
|
delete |
|
delete |
|
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().
|
inlinenodiscard |
Initializes the client.
Connects to the server endpoints and starts the response handler thread.
error_fatal | treat 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. |
Definition at line 71 of file tcp_client.hpp.
References cbdc::network::connection_manager::cluster_connect(), and cbdc::network::connection_manager::start_handler().
|
delete |
|
delete |