Open Lighting Architecture  Latest Git
Classes | Public Types | Public Member Functions | List of all members
ola::network::AdvancedTCPConnector Class Reference

Detailed Description

Attempts to open a TCP connection until a failure limit is reached.

The AdvancedTCPConnector attempts to open connections to a endpoint. If the connection fails it will retry according to a given BackOffPolicy.


Public Types

 The state of a connection. More...

Public Member Functions

 AdvancedTCPConnector (ola::io::SelectServerInterface *ss, TCPSocketFactoryInterface *socket_factory, const ola::TimeInterval &connection_timeout)
 Create a new AdvancedTCPConnector. More...
void AddEndpoint (const IPV4SocketAddress &endpoint, BackOffPolicy *backoff_policy, bool paused=false)
 Add an endpoint to manage a connection to. More...
void RemoveEndpoint (const IPV4SocketAddress &endpoint)
 Remove a IP:Port from the connection manager. This won't close the connection if it's already established. More...
unsigned int EndpointCount () const
 Return the number of connections tracked by this connector.
bool GetEndpointState (const IPV4SocketAddress &endpoint, ConnectionState *connected, unsigned int *failed_attempts) const
 Get the state & number of failed_attempts for an endpoint. More...
void Disconnect (const IPV4SocketAddress &endpoint, bool pause=false)
 Mark an endpoint as disconnected. More...
void Resume (const IPV4SocketAddress &endpoint)
 Resume trying to connect to a ip:port pair. More...

Member Enumeration Documentation

◆ ConnectionState

The state of a connection.


The socket is disconnected


The socket is disconnected, and will not be retried.


The socket is connected.

Constructor & Destructor Documentation

◆ AdvancedTCPConnector()

ola::network::AdvancedTCPConnector::AdvancedTCPConnector ( ola::io::SelectServerInterface ss,
TCPSocketFactoryInterface socket_factory,
const ola::TimeInterval connection_timeout 

Create a new AdvancedTCPConnector.

ssthe SelectServerInterface to use for scheduling
socket_factorythe factory to use for creating new sockets
connection_timeoutthe timeout for TCP connects.

Member Function Documentation

◆ AddEndpoint()

void ola::network::AdvancedTCPConnector::AddEndpoint ( const IPV4SocketAddress endpoint,
BackOffPolicy backoff_policy,
bool  paused = false 

Add an endpoint to manage a connection to.

If the IP:Port already exists this won't do anything. When the connection is successful the on_connect callback will be run, and ownership of the TCPSocket object is transferred.

endpointthe IPV4SocketAddress to connect to.
backoff_policythe BackOffPolicy to use for this connection.
pausedtrue if we don't want to immediately connect to this peer.

◆ Disconnect()

void ola::network::AdvancedTCPConnector::Disconnect ( const IPV4SocketAddress endpoint,
bool  pause = false 

Mark an endpoint as disconnected.

endpointthe IPV4SocketAddress to mark as disconnected.
pauseif true, don't immediately try to reconnect.

◆ GetEndpointState()

bool ola::network::AdvancedTCPConnector::GetEndpointState ( const IPV4SocketAddress endpoint,
ConnectionState connected,
unsigned int *  failed_attempts 
) const

Get the state & number of failed_attempts for an endpoint.

endpointthe IPV4SocketAddress to get the state of.
[out]connectedthe connection state for this endpoint.
[out]failed_attemptsthe number of failed connects for this endpoint.
true if this endpoint was found, false otherwise.

◆ RemoveEndpoint()

void ola::network::AdvancedTCPConnector::RemoveEndpoint ( const IPV4SocketAddress endpoint)

Remove a IP:Port from the connection manager. This won't close the connection if it's already established.

endpointthe IPV4SocketAddress to remove.

◆ Resume()

void ola::network::AdvancedTCPConnector::Resume ( const IPV4SocketAddress endpoint)

Resume trying to connect to a ip:port pair.

endpointthe IPV4SocketAddress to resume connecting for.

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