Async 1.8.0
|
A base class for creating a prio controlled TCP client connection. More...
#include <AsyncTcpPrioClientBase.h>
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 TcpClientBase & | operator= (TcpClientBase &&other) |
Inherit the assignment operator from 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 IpAddress & | bindIp (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. | |
TcpConnection * | conObj (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 TcpClientBase * | newTcpClient (void)=0 |
Allocate a new TcpClient object. | |
virtual void | emitDisconnected (TcpConnection::DisconnectReason reason)=0 |
Emit the disconnected signal. | |
![]() | |
virtual void | closeConnection (void) |
Check if the connection has been fully connected. | |
virtual void | emitConnected (void) |
Additional Inherited Members | |
![]() | |
sigc::signal< void > | connected |
A signal that is emitted when a connection has been established. | |
A base class for creating a prio controlled TCP client connection.
This is the base class for creating prioritized TCP connections. See Async::TcpPrioClient for more information.
Definition at line 116 of file AsyncTcpPrioClientBase.h.
|
explicit |
Constructor.
con | The 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.
|
delete |
Deleted constructor not making sense in this context.
|
delete |
Deleted constructor not making sense in this context.
|
virtual |
Destructor.
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.
ttl | The time-to-live for the record |
prio | The priority for the record, lower mean higher |
weight | The weight for records with the same priority |
port | The network port for the service |
target | The 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.
|
delete |
Deleted function not making sense in this context.
|
delete |
Deleted function not making sense in this context.
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.
|
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.
|
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().
|
protectedpure virtual |
Emit the disconnected signal.
reason | The reason for the disconnection |
Implemented in Async::TcpPrioClient< ConT >.
bool Async::TcpPrioClientBase::isIdle | ( | void | ) | const |
Check if the connection is idle.
A connection being idle means that it is not connected nor connecting.
bool Async::TcpPrioClientBase::isPrimary | ( | void | ) | const |
Check if connected to the primary server.
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.
bool Async::TcpPrioClientBase::markedAsEstablished | ( | void | ) | const |
Check if a connection has been marked as established.
|
protectedpure virtual |
Allocate 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 >.
|
protectedvirtual |
Called when a connection has been terminated.
reason | The 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().
|
virtual |
Inherit the assignment operator from TcpClientBase.
Reimplemented from Async::TcpClientBase.
const std::string & Async::TcpPrioClientBase::service | ( | void | ) | const |
Get the full service name.
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.
void Async::TcpPrioClientBase::setReconnectBackoffPercent | ( | unsigned | p | ) |
Percent to increase reconnect time with each try.
p | Percent |
void Async::TcpPrioClientBase::setReconnectMaxTime | ( | unsigned | t | ) |
Maximum time between reconnects.
t | Time in milliseconds |
void Async::TcpPrioClientBase::setReconnectMinTime | ( | unsigned | t | ) |
Minimum time between reconnects.
t | Time in milliseconds |
void Async::TcpPrioClientBase::setReconnectRandomizePercent | ( | unsigned | p | ) |
Percent to randomize reconnect time.
p | Percent |
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.
srv_name | The name of the service |
srv_proto | The protocol for the service (e.g. tcp or udp) |
srv_domain | The 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.