Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
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.

Limitations:

  • This class only supports a single connection per IP:Port.
  • This class should work fine for a small number of TCP connections (100 or so). It'll need to be re-written if we want to support 1000s.

Public Types

enum  ConnectionState { DISCONNECTED , PAUSED , CONNECTED }
 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.
 
void AddEndpoint (const IPV4SocketAddress &endpoint, BackOffPolicy *backoff_policy, bool paused=false)
 Add an endpoint to manage a connection to.
 
void RemoveEndpoint (const IPV4SocketAddress &endpoint)
 Remove a IP:Port from the connection manager. This won't close the connection if it's already established.
 
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.
 
void Disconnect (const IPV4SocketAddress &endpoint, bool pause=false)
 Mark an endpoint as disconnected.
 
void Resume (const IPV4SocketAddress &endpoint)
 Resume trying to connect to a ip:port pair.
 

Member Enumeration Documentation

◆ ConnectionState

The state of a connection.

Enumerator
DISCONNECTED 

The socket is disconnected

PAUSED 

The socket is disconnected, and will not be retried.

CONNECTED 

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.

Parameters
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.

Parameters
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.

Parameters
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.

Parameters
endpointthe IPV4SocketAddress to get the state of.
[out]connectedthe connection state for this endpoint.
[out]failed_attemptsthe number of failed connects for this endpoint.
Returns
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.

Parameters
endpointthe IPV4SocketAddress to remove.

◆ Resume()

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

Resume trying to connect to a ip:port pair.

Parameters
endpointthe IPV4SocketAddress to resume connecting for.

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