Open Lighting Architecture
0.9.0
|
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 | |
TCPSocketFactoryInterface * | m_socket_factory |
ola::network::AdvancedTCPConnector::AdvancedTCPConnector | ( | ola::io::SelectServerInterface * | ss, |
TCPSocketFactoryInterface * | socket_factory, | ||
const ola::TimeInterval & | connection_timeout | ||
) |
Create a new AdvancedTCPConnector
ss | the SelectServerInterface to use for scheduling |
socket_factory | the factory to use for creating new sockets |
connection_timeout | the timeout for TCP connects |
|
virtual |
Cancel all outstanding connections.
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.
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. |
void ola::network::AdvancedTCPConnector::Disconnect | ( | const IPV4SocketAddress & | endpoint, |
bool | pause = false |
||
) |
Mark a host as disconnected.
endpoint | the IPV4SocketAddress to mark as disconnected. |
pause | if 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
endpoint | the IPV4SocketAddress to get the state of. |
void ola::network::AdvancedTCPConnector::RemoveEndpoint | ( | const IPV4SocketAddress & | endpoint | ) |
Remove a ip:port from the connection manager. This won't close the connection.
endpoint | the IPV4SocketAddress to remove. |
void ola::network::AdvancedTCPConnector::Resume | ( | const IPV4SocketAddress & | endpoint | ) |
Resume trying to connect to a ip:port pair.
|
protected |
Schedule the re-try attempt for this connection
|
protectedvirtual |
Sub classes can override this to tune the behavior
Decide what to do when a connection fails, completes or times out.