Async 1.8.0
Async::TcpClientBase Class Referenceabstract

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

#include <AsyncTcpClientBase.h>

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

Public Member Functions

 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.
 
virtual TcpClientBaseoperator= (TcpClientBase &&other)
 Move assignmnt operator.
 
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.
 
virtual void disconnect (void)=0
 Disconnect from the remote host.
 
bool isIdle (void) const
 Check if the connection is idle.
 
TcpConnectionconObj (void)
 Return the connection object for this client connection.
 

Public Attributes

sigc::signal< void > connected
 A signal that is emitted when a connection has been established.
 

Protected Member Functions

virtual void closeConnection (void)
 Check if the connection has been fully connected.
 
virtual void connectionEstablished (void)
 Called when the connection has been established to the server.
 
virtual void emitConnected (void)
 

Detailed Description

A base class for creating a TCP client connection.

Author
Tobias Blomberg
Date
2003-04-12

This is a base class for creating TCP client connections. It should notmally not be used direclt but rather the TcpClient class should be used.

Definition at line 121 of file AsyncTcpClientBase.h.

Constructor & Destructor Documentation

◆ TcpClientBase() [1/3]

Async::TcpClientBase::TcpClientBase ( 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.

◆ TcpClientBase() [2/3]

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

Constructor.

Parameters
conThe connection object associated with this client
remote_hostThe hostname of the remote host
remote_portThe port on the remote host to connect to

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.

◆ TcpClientBase() [3/3]

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

Constructor.

Parameters
conThe connection object associated with this client
remote_ipThe IP address of the remote host
remote_portThe port on the remote host to connect to

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.

◆ ~TcpClientBase()

virtual Async::TcpClientBase::~TcpClientBase ( void )
virtual

Destructor.

Member Function Documentation

◆ bindIp()

const IpAddress & Async::TcpClientBase::bindIp ( void ) const
inline

Get the bind IP address.

Returns
Returns the bind IP address

Definition at line 201 of file AsyncTcpClientBase.h.

◆ closeConnection()

virtual void Async::TcpClientBase::closeConnection ( void )
protectedvirtual

Check if the connection has been fully connected.

Returns
Return true if the connection was successful

This function return true when the connection has been fully established. It will continue to return true even after disconnection and will be reset at the moment when a new connection attempt is made.

Disconnect from the remote peer

This function is used internally to close the connection to the remote peer.

Reimplemented in Async::TcpClient< ConT >, and Async::TcpPrioClient< ConT >.

Referenced by Async::TcpClient< ConT >::closeConnection(), and Async::TcpPrioClient< ConT >::closeConnection().

◆ connect() [1/3]

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

Connect to the remote host.

Parameters
remote_ipThe IP address of the remote host
remote_portThe port on the remote host to connect to

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

◆ connect() [2/3]

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

Connect to the remote host.

Parameters
remote_hostThe hostname of the remote host
remote_portThe port on the remote host to connect to

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

◆ connect() [3/3]

void Async::TcpClientBase::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 TcpClient::connected) has been emitted. If the connection is already established or pending, an assertion will be raised.

◆ connectionEstablished()

virtual void Async::TcpClientBase::connectionEstablished ( void )
inlineprotectedvirtual

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 in Async::TcpPrioClientBase.

Definition at line 294 of file AsyncTcpClientBase.h.

References emitConnected().

◆ conObj()

TcpConnection * Async::TcpClientBase::conObj ( void )
inline

Return the connection object for this client connection.

Returns
Returns the connection object

Definition at line 258 of file AsyncTcpClientBase.h.

◆ disconnect()

virtual void Async::TcpClientBase::disconnect ( void )
pure 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

Implemented in Async::TcpClient< ConT >, Async::TcpPrioClient< ConT >, and Async::TcpPrioClientBase.

◆ emitConnected()

virtual void Async::TcpClientBase::emitConnected ( void )
inlineprotectedvirtual

Definition at line 300 of file AsyncTcpClientBase.h.

References connected.

Referenced by connectionEstablished().

◆ isIdle()

bool Async::TcpClientBase::isIdle ( void ) const
inline

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.

Definition at line 252 of file AsyncTcpClientBase.h.

References Async::DnsLookup::isPending().

Referenced by Async::TcpClient< ConT >::isIdle().

◆ operator=()

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

Move assignmnt operator.

Parameters
otherThe object to move from
Returns
Returns this object

Reimplemented in Async::TcpClient< ConT >, and Async::TcpPrioClientBase.

◆ remoteHostName()

std::string Async::TcpClientBase::remoteHostName ( void ) const
inline

Get the name of the remote host as given to connect()

Returns
Returns the name of the remote host

This function return the name of the remote host as it was given to the connect call. If an IP address was used the text representation of that will be returned.

Examples
AsyncTcpClient_demo.cpp.

Definition at line 182 of file AsyncTcpClientBase.h.

References Async::DnsLookup::label(), Async::TcpConnection::remoteHost(), and Async::IpAddress::toString().

◆ setBindIp()

void Async::TcpClientBase::setBindIp ( const IpAddress & bind_ip)

Bind to the interface having the specified IP address.

Parameters
bind_ipThe IP address of the interface to bind to

Member Data Documentation

◆ connected

sigc::signal<void> Async::TcpClientBase::connected

A signal that is emitted when a connection has been established.

Examples
AsyncTcpPrioClient_demo.cpp.

Definition at line 263 of file AsyncTcpClientBase.h.

Referenced by emitConnected().


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