WPILibC++ 2024.3.2
|
Parallel TCP connector. More...
#include <wpinet/ParallelTcpConnector.h>
Public Member Functions | |
ParallelTcpConnector (wpi::uv::Loop &loop, wpi::uv::Timer::Time reconnectRate, wpi::Logger &logger, std::function< void(wpi::uv::Tcp &tcp)> connected, const private_init &) | |
~ParallelTcpConnector () | |
ParallelTcpConnector (const ParallelTcpConnector &)=delete | |
ParallelTcpConnector & | operator= (const ParallelTcpConnector &)=delete |
void | Close () |
Closes resources, canceling all pending action attempts. More... | |
void | SetServers (std::span< const std::pair< std::string, unsigned int > > servers) |
Changes the servers/ports to connect to. More... | |
void | Disconnected () |
Tells the parallel connector that the current connection has terminated and it is necessary to start reconnection attempts. More... | |
void | Succeeded (wpi::uv::Tcp &tcp) |
Tells the parallel connector that a particular connection has succeeded and it should stop trying to connect. More... | |
Static Public Member Functions | |
static std::shared_ptr< ParallelTcpConnector > | Create (wpi::uv::Loop &loop, wpi::uv::Timer::Time reconnectRate, wpi::Logger &logger, std::function< void(wpi::uv::Tcp &tcp)> connected) |
Create. More... | |
Parallel TCP connector.
Attempts parallel resolution and connection to multiple servers with automatic retry if none connect.
Each successful TCP connection results in a call to the connected callback. For correct operation, the consuming code (either the connected callback or e.g. task it starts) must call Succeeded() to indicate if the connection has succeeded prior to the reconnect rate timeout. A successful connection results in the connector terminating all other connection attempts.
After the reconnect rate times out, all remaining active connection attempts are canceled and new ones started.
wpi::ParallelTcpConnector::ParallelTcpConnector | ( | wpi::uv::Loop & | loop, |
wpi::uv::Timer::Time | reconnectRate, | ||
wpi::Logger & | logger, | ||
std::function< void(wpi::uv::Tcp &tcp)> | connected, | ||
const private_init & | |||
) |
wpi::ParallelTcpConnector::~ParallelTcpConnector | ( | ) |
|
delete |
void wpi::ParallelTcpConnector::Close | ( | ) |
Closes resources, canceling all pending action attempts.
|
inlinestatic |
Create.
loop | loop |
reconnectRate | how long to wait after starting connection attempts to cancel and attempt connecting again |
logger | logger |
connected | callback function when a connection succeeds; may be called multiple times if it does not call Succeeded() before returning |
void wpi::ParallelTcpConnector::Disconnected | ( | ) |
Tells the parallel connector that the current connection has terminated and it is necessary to start reconnection attempts.
|
delete |
void wpi::ParallelTcpConnector::SetServers | ( | std::span< const std::pair< std::string, unsigned int > > | servers | ) |
Changes the servers/ports to connect to.
Starts connection attempts if not already connected.
servers | array of server/port pairs |
void wpi::ParallelTcpConnector::Succeeded | ( | wpi::uv::Tcp & | tcp | ) |
Tells the parallel connector that a particular connection has succeeded and it should stop trying to connect.
tcp | connection passed to connected callback |