WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
wpi::ParallelTcpConnector Class Reference

Parallel TCP connector. More...

#include <wpinet/ParallelTcpConnector.h>

Inheritance diagram for wpi::ParallelTcpConnector:

Public Member Functions

 ParallelTcpConnector (wpi::uv::Loop &loop, wpi::uv::Timer::Time reconnectRate, wpi::Logger &logger, std::function< void(wpi::uv::Tcp &tcp)> connected, bool ipv4Only, const private_init &)
 
 ~ParallelTcpConnector ()
 
 ParallelTcpConnector (const ParallelTcpConnector &)=delete
 
ParallelTcpConnectoroperator= (const ParallelTcpConnector &)=delete
 
void Close ()
 Closes resources, canceling all pending action attempts.
 
void SetServers (std::span< const std::pair< std::string, unsigned int > > servers)
 Changes the servers/ports to connect to.
 
void Disconnected ()
 Tells the parallel connector that the current connection has terminated and it is necessary to start reconnection attempts.
 
void Succeeded (wpi::uv::Tcp &tcp)
 Tells the parallel connector that a particular connection has succeeded and it should stop trying to connect.
 

Static Public Member Functions

static std::shared_ptr< ParallelTcpConnectorCreate (wpi::uv::Loop &loop, wpi::uv::Timer::Time reconnectRate, wpi::Logger &logger, std::function< void(wpi::uv::Tcp &tcp)> connected, bool ipv4Only=false)
 Create.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ParallelTcpConnector() [1/2]

wpi::ParallelTcpConnector::ParallelTcpConnector ( wpi::uv::Loop & loop,
wpi::uv::Timer::Time reconnectRate,
wpi::Logger & logger,
std::function< void(wpi::uv::Tcp &tcp)> connected,
bool ipv4Only,
const private_init &  )

◆ ~ParallelTcpConnector()

wpi::ParallelTcpConnector::~ParallelTcpConnector ( )

◆ ParallelTcpConnector() [2/2]

wpi::ParallelTcpConnector::ParallelTcpConnector ( const ParallelTcpConnector & )
delete

Member Function Documentation

◆ Close()

void wpi::ParallelTcpConnector::Close ( )

Closes resources, canceling all pending action attempts.

◆ Create()

static std::shared_ptr< ParallelTcpConnector > wpi::ParallelTcpConnector::Create ( wpi::uv::Loop & loop,
wpi::uv::Timer::Time reconnectRate,
wpi::Logger & logger,
std::function< void(wpi::uv::Tcp &tcp)> connected,
bool ipv4Only = false )
inlinestatic

Create.

Parameters
looploop
reconnectRatehow long to wait after starting connection attempts to cancel and attempt connecting again
loggerlogger
connectedcallback function when a connection succeeds; may be called multiple times if it does not call Succeeded() before returning
ipv4Onlytrue if only IPv4 addresses should be returned; otherwise both IPv4 and IPv6 addresses are returned
Returns
Parallel connector

◆ Disconnected()

void wpi::ParallelTcpConnector::Disconnected ( )

Tells the parallel connector that the current connection has terminated and it is necessary to start reconnection attempts.

◆ operator=()

ParallelTcpConnector & wpi::ParallelTcpConnector::operator= ( const ParallelTcpConnector & )
delete

◆ SetServers()

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.

Parameters
serversarray of server/port pairs

◆ Succeeded()

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.

Parameters
tcpconnection passed to connected callback

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