WPILibC++ 2023.4.3-108-ge5452e3
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, const private_init &)
 
 ~ParallelTcpConnector ()
 
 ParallelTcpConnector (const ParallelTcpConnector &)=delete
 
ParallelTcpConnectoroperator= (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< ParallelTcpConnectorCreate (wpi::uv::Loop &loop, wpi::uv::Timer::Time reconnectRate, wpi::Logger &logger, std::function< void(wpi::uv::Tcp &tcp)> connected)
 Create. More...
 

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,
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 
)
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
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: