Open Lighting Architecture: ola::network::AdvancedTCPConnector Class Reference

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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.

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

enum ola::network::AdvancedTCPConnector::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

  ss | the SelectServerInterface to use for scheduling
  socket_factory | the factory to use for creating new sockets
  connection_timeout | the 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

  endpoint | the IPV4SocketAddress to connect to.
  backoff_policy | the BackOffPolicy to use for this connection.
  paused | true 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

  endpoint | the IPV4SocketAddress to mark as disconnected.
  pause | if 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

  | endpoint | the IPV4SocketAddress to get the state of.
  [out] | connected | the connection state for this endpoint.
  [out] | failed_attempts | the 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

  endpoint | the IPV4SocketAddress to remove.

## ◆ Resume()

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

Resume trying to connect to a ip:port pair.

Parameters

  endpoint | the IPV4SocketAddress to resume connecting for.

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

- include/ola/network/AdvancedTCPConnector.h
- common/network/AdvancedTCPConnector.cpp