Async 1.8.0
Async::TcpPrioClientBase Class Referenceabstract

A base class for creating a prio controlled TCP client connection. More...

#include <AsyncTcpPrioClientBase.h>

Inheritance diagram for Async::TcpPrioClientBase:
Async::TcpClientBase Async::TcpPrioClient< ConT >

Public Member Functions

 TcpPrioClientBase (TcpConnection *con)
 Constructor.
 
 TcpPrioClientBase (TcpConnection *con, const std::string &remote_host, uint16_t remote_port)=delete
 Deleted constructor not making sense in this context.
 
 TcpPrioClientBase (TcpConnection *con, const IpAddress &remote_ip, uint16_t remote_port)=delete
 Deleted constructor not making sense in this context.
 
virtual ~TcpPrioClientBase (void)
 Destructor.
 
void setReconnectMinTime (unsigned t)
 Minimum time between reconnects.
 
void setReconnectMaxTime (unsigned t)
 Maximum time between reconnects.
 
void setReconnectBackoffPercent (unsigned p)
 Percent to increase reconnect time with each try.
 
void setReconnectRandomizePercent (unsigned p)
 Percent to randomize reconnect time.
 
void setService (const std::string &srv_name, const std::string &srv_proto, const std::string &srv_domain)
 Use a DNS service resource record for connections.
 
void addStaticSRVRecord (DnsResourceRecordSRV::Ttl ttl, DnsResourceRecordSRV::Prio prio, DnsResourceRecordSRV::Weight weight, DnsResourceRecordSRV::Port port, DnsResourceRecordSRV::Target target)
 Add a static service resource record.
 
const std::string & service (void) const
 Get the full service name.
 
void connect (void)
 Connect to the remote host.
 
void connect (const std::string &remote_host, uint16_t remote_port)=delete
 Deleted function not making sense in this context.
 
void connect (const Async::IpAddress &remote_ip, uint16_t remote_port)=delete
 Deleted function not making sense in this context.
 
virtual void disconnect (void)
 Disconnect from the remote host.
 
void markAsEstablished (void)
 Mark connection as established.
 
bool markedAsEstablished (void) const
 Check if a connection has been marked as established.
 
bool isIdle (void) const
 Check if the connection is idle.
 
bool isPrimary (void) const
 Check if connected to the primary server.
 
virtual TcpClientBaseoperator= (TcpClientBase &&other)
 Inherit the assignment operator from TcpClientBase.
 
- Public Member Functions inherited from Async::TcpClientBase
 TcpClientBase (TcpConnection *con)
 Constructor.
 
 TcpClientBase (TcpConnection *con, const std::string &remote_host, uint16_t remote_port)
 Constructor.
 
 TcpClientBase (TcpConnection *con, const IpAddress &remote_ip, uint16_t remote_port)
 Constructor.
 
virtual ~TcpClientBase (void)
 Destructor.
 
std::string remoteHostName (void) const
 Get the name of the remote host as given to connect()
 
void setBindIp (const IpAddress &bind_ip)
 Bind to the interface having the specified IP address.
 
const IpAddressbindIp (void) const
 Get the bind IP address.
 
void connect (const std::string &remote_host, uint16_t remote_port)
 Connect to the remote host.
 
void connect (const Async::IpAddress &remote_ip, uint16_t remote_port)
 Connect to the remote host.
 
void connect (void)
 Connect to the remote host.
 
bool isIdle (void) const
 Check if the connection is idle.
 
TcpConnectionconObj (void)
 Return the connection object for this client connection.
 

Protected Member Functions

virtual void connectionEstablished (void) override
 Called when the connection has been established to the server.
 
virtual void onDisconnected (TcpConnection::DisconnectReason reason)
 Called when a connection has been terminated.
 
virtual TcpClientBasenewTcpClient (void)=0
 Allocate a new TcpClient object.
 
virtual void emitDisconnected (TcpConnection::DisconnectReason reason)=0
 Emit the disconnected signal.
 
- Protected Member Functions inherited from Async::TcpClientBase
virtual void closeConnection (void)
 Check if the connection has been fully connected.
 
virtual void emitConnected (void)
 

Additional Inherited Members

- Public Attributes inherited from Async::TcpClientBase
sigc::signal< void > connected
 A signal that is emitted when a connection has been established.
 

Detailed Description

A base class for creating a prio controlled TCP client connection.

Author
Tobias Blomberg
Date
2022-02-12

This is the base class for creating prioritized TCP connections. See Async::TcpPrioClient for more information.

Definition at line 116 of file AsyncTcpPrioClientBase.h.

Constructor & Destructor Documentation

◆ TcpPrioClientBase() [1/3]

Async::TcpPrioClientBase::TcpPrioClientBase ( TcpConnection * con)
explicit

Constructor.

Parameters
conThe connection object associated with this client

The object will be constructed and variables will be initialized but no connection will be created until the connect function (see TcpClient::connect) is called. When using this variant of the constructor the connect method which take host and port must be used.

◆ TcpPrioClientBase() [2/3]

Async::TcpPrioClientBase::TcpPrioClientBase ( TcpConnection * con,
const std::string & remote_host,
uint16_t remote_port )
delete

Deleted constructor not making sense in this context.

◆ TcpPrioClientBase() [3/3]

Async::TcpPrioClientBase::TcpPrioClientBase ( TcpConnection * con,
const IpAddress & remote_ip,
uint16_t remote_port )
delete

Deleted constructor not making sense in this context.

◆ ~TcpPrioClientBase()

virtual Async::TcpPrioClientBase::~TcpPrioClientBase ( void )
virtual

Destructor.

Member Function Documentation

◆ addStaticSRVRecord()

void Async::TcpPrioClientBase::addStaticSRVRecord ( DnsResourceRecordSRV::Ttl ttl,
DnsResourceRecordSRV::Prio prio,
DnsResourceRecordSRV::Weight weight,
DnsResourceRecordSRV::Port port,
DnsResourceRecordSRV::Target target )

Add a static service resource record.

Parameters
ttlThe time-to-live for the record
prioThe priority for the record, lower mean higher
weightThe weight for records with the same priority
portThe network port for the service
targetThe FQDN of the host where the service is hosted

Use this function to add static SRV records. This may be useful if there is no DNS service available or if it does not have SRV record support. It may also be used to add more records to a DNS answer.

The added records will survive over the whole lifetime of the DNS object and will be added to all DNS lookups made during that time.

If the setService() function have been used to set up the service parameters, the name of the static service records will be the same as for the whole service name. If no service parameters have been set up the name of the records will be set to "static".

NOTE: The target should normally be an FQDN but it is also possible to specify an IP address or unqualified hostname.

Setting the TTL to zero has a special meaning when combined with real DNS records from a DNS lookup. If any records are found in the DNS the TTL for the static records will be set to the maximum value. If no records are found in the DNS the TTL will be zero.

◆ connect() [1/3]

void Async::TcpPrioClientBase::connect ( const Async::IpAddress & remote_ip,
uint16_t remote_port )
delete

Deleted function not making sense in this context.

◆ connect() [2/3]

void Async::TcpPrioClientBase::connect ( const std::string & remote_host,
uint16_t remote_port )
delete

Deleted function not making sense in this context.

◆ connect() [3/3]

void Async::TcpPrioClientBase::connect ( void )

Connect to the remote host.

This function will initiate a connection to the remote host. The connection must not be written to before the connected signal (see TcpClientBase::connected) has been emitted. If the connection is already established or pending, nothing will be done.

◆ connectionEstablished()

virtual void Async::TcpPrioClientBase::connectionEstablished ( void )
overrideprotectedvirtual

Called when the connection has been established to the server.

This function may be overridden by inheriting classes to get informed of when a connection has been established. The overriding function should normally call this function.

Reimplemented from Async::TcpClientBase.

◆ disconnect()

virtual void Async::TcpPrioClientBase::disconnect ( void )
virtual

Disconnect from the remote host.

Call this function to disconnect from the remote host. If already disconnected, nothing will be done. The disconnected signal is not emitted when this function is called

Implements Async::TcpClientBase.

Reimplemented in Async::TcpPrioClient< ConT >.

Referenced by Async::TcpPrioClient< ConT >::disconnect().

◆ emitDisconnected()

virtual void Async::TcpPrioClientBase::emitDisconnected ( TcpConnection::DisconnectReason reason)
protectedpure virtual

Emit the disconnected signal.

Parameters
reasonThe reason for the disconnection

Implemented in Async::TcpPrioClient< ConT >.

◆ isIdle()

bool Async::TcpPrioClientBase::isIdle ( void ) const

Check if the connection is idle.

Returns
Returns true if the connection is idle

A connection being idle means that it is not connected nor connecting.

◆ isPrimary()

bool Async::TcpPrioClientBase::isPrimary ( void ) const

Check if connected to the primary server.

◆ markAsEstablished()

void Async::TcpPrioClientBase::markAsEstablished ( void )

Mark connection as established.

The application must use this function to mark a connection as established when the application layer deem the connection as successful. It is up to the application to decide this, e.g. after the connection has been authenticated. If a connection has not been marked as established when a disconnection occurs, a new connection will be tried again after the exponential backoff timer has expired. On the other hand, if the connection has been marked as established, a reconnect will be retried after the minimal reconnect delay.

◆ markedAsEstablished()

bool Async::TcpPrioClientBase::markedAsEstablished ( void ) const

Check if a connection has been marked as established.

◆ newTcpClient()

virtual TcpClientBase * Async::TcpPrioClientBase::newTcpClient ( void )
protectedpure virtual

Allocate a new TcpClient object.

Returns
Returns a new TcpClient object

This function is used to allocate a new TcpClient object. That object is used when in the background trying to connect to a higher prioritized server. Note that the object should be a "normal" TcpClient and not a TcpPrioClient.

Implemented in Async::TcpPrioClient< ConT >.

◆ onDisconnected()

virtual void Async::TcpPrioClientBase::onDisconnected ( TcpConnection::DisconnectReason reason)
protectedvirtual

Called when a connection has been terminated.

Parameters
reasonThe reason for the disconnect

This function will be called when the connection has been terminated.

Reimplemented in Async::TcpPrioClient< ConT >.

Referenced by Async::TcpPrioClient< ConT >::onDisconnected().

◆ operator=()

virtual TcpClientBase & Async::TcpClientBase::operator= ( TcpClientBase && other)
virtual

Inherit the assignment operator from TcpClientBase.

Reimplemented from Async::TcpClientBase.

◆ service()

const std::string & Async::TcpPrioClientBase::service ( void ) const

Get the full service name.

Returns
Return the full name of the service

This function fill return the full name of the service as set up by the setService() function. If no service has been set up, an empty string will returned.

◆ setReconnectBackoffPercent()

void Async::TcpPrioClientBase::setReconnectBackoffPercent ( unsigned p)

Percent to increase reconnect time with each try.

Parameters
pPercent

◆ setReconnectMaxTime()

void Async::TcpPrioClientBase::setReconnectMaxTime ( unsigned t)

Maximum time between reconnects.

Parameters
tTime in milliseconds

◆ setReconnectMinTime()

void Async::TcpPrioClientBase::setReconnectMinTime ( unsigned t)

Minimum time between reconnects.

Parameters
tTime in milliseconds

◆ setReconnectRandomizePercent()

void Async::TcpPrioClientBase::setReconnectRandomizePercent ( unsigned p)

Percent to randomize reconnect time.

Parameters
pPercent

◆ setService()

void Async::TcpPrioClientBase::setService ( const std::string & srv_name,
const std::string & srv_proto,
const std::string & srv_domain )

Use a DNS service resource record for connections.

Parameters
srv_nameThe name of the service
srv_protoThe protocol for the service (e.g. tcp or udp)
srv_domainThe domain providing the service

This function will set up information for connecting to a remote host using SRV records in the DNS system. SRV records is a more advanced way of looking up host information in the DNS system where it is possible to load balance and prioritize between multiple hosts. Use the connect() function to actually start connecting.


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