OpenCBDC Transaction Processor
|
Maintains a TCP socket. More...
#include <peer.hpp>
Public Types | |
using | callback_type = std::function<void(std::shared_ptr<cbdc::buffer>)> |
Type for the packet receipt callback function. | |
Public Member Functions | |
peer (std::unique_ptr< tcp_socket > sock, callback_type cb, bool attempt_reconnect) | |
Constructor. | |
~peer () | |
Destructor. Calls shutdown(). | |
peer (const peer &)=delete | |
auto | operator= (const peer &) -> peer &=delete |
peer (peer &&)=delete | |
auto | operator= (peer &&) -> peer &=delete |
void | send (const std::shared_ptr< cbdc::buffer > &data) |
Sends buffered data. | |
void | shutdown () |
Clears any packets in the pending send queue. | |
auto | connected () const -> bool |
Indicates whether the TCP socket is currently connected. | |
Maintains a TCP socket.
Handles reconnecting to a TCP socket, queuing discrete packets to send, sending queued packets, and passing received packets to a callback function.
using cbdc::network::peer::callback_type = std::function<void(std::shared_ptr<cbdc::buffer>)> |
cbdc::network::peer::peer | ( | std::unique_ptr< tcp_socket > | sock, |
peer::callback_type | cb, | ||
bool | attempt_reconnect ) |
Constructor.
Starts socket management threads.
Starts a thread to send queued packets via the associated TCP socket. Starts a thread to receive packets and call a callback function. Starts a thread to monitor the connection status of the TCP socket and reconnect if the socket disconnects.
sock | TCP socket to manage. |
cb | callback function to call with packets received by the socket. |
attempt_reconnect | true if the instance should reconnect the TCP socket if it loses the connection. |
cbdc::network::peer::~peer | ( | ) |
Destructor. Calls shutdown().
Definition at line 23 of file peer.cpp.
References shutdown().
|
delete |
|
delete |
|
nodiscard |
void cbdc::network::peer::send | ( | const std::shared_ptr< cbdc::buffer > & | data | ) |
Sends buffered data.
Queues a packet to send via the TCP socket. The recipient peer receives it as a discrete unit.
data | buffer to send. |
Definition at line 27 of file peer.cpp.
Referenced by cbdc::network::connection_manager::broadcast(), and cbdc::network::connection_manager::send().
void cbdc::network::peer::shutdown | ( | ) |
Clears any packets in the pending send queue.
Stops the send, receive, and reconnect threads. Disconnects the TCP socket.
Definition at line 33 of file peer.cpp.
Referenced by cbdc::network::connection_manager::close(), and ~peer().