Open Lighting Architecture  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
ola::network::AdvancedTCPConnector Class Reference

Detailed Description

Manages the TCP connections to ip:ports. The AdvancedTCPConnector attempts to open connections to ip:ports, backing off exponentially if we can't connect.

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

Classes

struct  ConnectionInfo

Public Types

enum  ConnectionState { DISCONNECTED, PAUSED, CONNECTED }

Public Member Functions

 AdvancedTCPConnector (ola::io::SelectServerInterface *ss, TCPSocketFactoryInterface *socket_factory, const ola::TimeInterval &connection_timeout)
virtual ~AdvancedTCPConnector ()
void AddEndpoint (const IPV4SocketAddress &endpoint, BackOffPolicy *backoff_policy, bool paused=false)
void RemoveEndpoint (const IPV4SocketAddress &endpoint)
unsigned int EndpointCount () const
bool GetEndpointState (const IPV4SocketAddress &endpoint, ConnectionState *connected, unsigned int *failed_attempts) const
void Disconnect (const IPV4SocketAddress &endpoint, bool pause=false)
void Resume (const IPV4SocketAddress &endpoint)

Protected Types

typedef std::pair< IPV4Address,
uint16_t > 
IPPortPair

Protected Member Functions

virtual void TakeAction (const IPPortPair &key, ConnectionInfo *info, int fd, int error)
void ScheduleRetry (const IPPortPair &key, ConnectionInfo *info)

Protected Attributes

TCPSocketFactoryInterfacem_socket_factory

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
ola::network::AdvancedTCPConnector::~AdvancedTCPConnector ( )
virtual

Cancel all outstanding connections.

Member Function Documentation

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

Add a remote host. This will trigger the connection process to start. 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 a host 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.
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.

Parameters
endpointthe IPV4SocketAddress to remove.
void ola::network::AdvancedTCPConnector::Resume ( const IPV4SocketAddress endpoint)

Resume trying to connect to a ip:port pair.

void ola::network::AdvancedTCPConnector::ScheduleRetry ( const IPPortPair &  key,
ConnectionInfo info 
)
protected

Schedule the re-try attempt for this connection

void ola::network::AdvancedTCPConnector::TakeAction ( const IPPortPair &  key,
ConnectionInfo info,
int  fd,
int  error 
)
protectedvirtual

Sub classes can override this to tune the behavior

Decide what to do when a connection fails, completes or times out.


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