Open Lighting Architecture  0.9.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.

Limitations:

Classes

struct  ConnectionInfo

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

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

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

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 successfull 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.
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.
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.
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.
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: