Async 1.8.0
|
A class for creating a TCP client connection. More...
#include <AsyncTcpClient.h>
Public Member Functions | |
TcpClient (size_t recv_buf_len=ConT::DEFAULT_RECV_BUF_LEN) | |
Constructor. | |
TcpClient (const std::string &remote_host, uint16_t remote_port, size_t recv_buf_len=ConT::DEFAULT_RECV_BUF_LEN) | |
Constructor. | |
TcpClient (const IpAddress &remote_ip, uint16_t remote_port, size_t recv_buf_len=ConT::DEFAULT_RECV_BUF_LEN) | |
Constructor. | |
~TcpClient (void) | |
Destructor. | |
virtual void | disconnect (void) override |
Disconnect from the remote host. | |
bool | isIdle (void) const |
Check if the connection is idle. | |
void | setSslContext (SslContext &ctx) |
![]() | |
TcpConnection (size_t recv_buf_len=DEFAULT_RECV_BUF_LEN) | |
Constructor. | |
TcpConnection (int sock, const IpAddress &remote_addr, uint16_t remote_port, size_t recv_buf_len=DEFAULT_RECV_BUF_LEN) | |
Constructor. | |
virtual | ~TcpConnection (void) |
Destructor. | |
virtual TcpConnection & | operator= (TcpConnection &&other) |
Move assignmnt operator. | |
void | setRecvBufLen (size_t recv_buf_len) |
Set a new receive buffer size. | |
size_t | recvBufLen (void) const |
virtual int | write (const void *buf, int count) |
Write data to the TCP connection. | |
IpAddress | localHost (void) const |
Get the local IP address associated with this connection. | |
uint16_t | localPort (void) const |
Get the local TCP port associated with this connection. | |
const IpAddress & | remoteHost (void) const |
Return the IP-address of the remote host. | |
uint16_t | remotePort (void) const |
Return the remote port used. | |
bool | isConnected (void) const |
Check if the connection is established or not. | |
bool | isIdle (void) const |
Check if the connection is idle. | |
void | enableSsl (bool enable) |
Enable or disable TLS for this connection. | |
SslX509 | sslPeerCertificate (void) |
Get the peer certificate associated with this connection. | |
Async::SslX509 | sslCertificate (void) const |
long | sslVerifyResult (void) const |
Get the result of the certificate verification process. | |
void | setSslContext (SslContext &ctx, bool is_server) |
Set the OpenSSL context to use when setting up the connection. | |
SslContext * | sslContext (void) |
bool | isServer (void) const |
void | freeze (void) |
Stop all communication. | |
void | unfreeze (void) |
Reenable all communication. | |
![]() | |
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 | closeConnection (void) override |
Disconnect from the remote peer. | |
virtual TcpClientBase & | operator= (TcpClientBase &&other) |
Move assignmnt operator. | |
![]() | |
void | setSocket (int sock) |
Setup information about the connection. | |
void | setRemoteAddr (const IpAddress &remote_addr) |
Setup information about the connection. | |
void | setRemotePort (uint16_t remote_port) |
Setup information about the connection. | |
int | socket (void) const |
Return the socket file descriptor. | |
virtual void | onDisconnected (DisconnectReason reason) |
Called when a connection has been terminated. | |
virtual int | onDataReceived (void *buf, int count) |
Called when data has been received on the connection. | |
virtual void | emitDisconnected (DisconnectReason reason) |
Emit the disconnected signal. | |
virtual int | emitVerifyPeer (int preverify_ok, X509_STORE_CTX *store_ctx) |
Emit the verifyPeer signal. | |
![]() | |
virtual void | connectionEstablished (void) |
Called when the connection has been established to the server. | |
virtual void | emitConnected (void) |
Additional Inherited Members | |
![]() | |
enum | DisconnectReason { DR_HOST_NOT_FOUND , DR_REMOTE_DISCONNECTED , DR_SYSTEM_ERROR , DR_ORDERED_DISCONNECT , DR_PROTOCOL_ERROR , DR_SWITCH_PEER , DR_BAD_STATE } |
Reason code for disconnects. More... | |
![]() | |
static const char * | disconnectReasonStr (DisconnectReason reason) |
Translate disconnect reason to a string. | |
![]() | |
sigc::signal< void, TcpConnection *, DisconnectReason > | disconnected |
Get common name for the SSL connection. | |
sigc::signal< int, TcpConnection *, void *, int > | dataReceived |
A signal that is emitted when data has been received on the connection. | |
sigc::signal< if_all_true_acc::result_type, TcpConnection *, int, X509_STORE_CTX * >::accumulated< if_all_true_acc > | verifyPeer |
A signal that is emitted on SSL/TLS certificate verification. | |
sigc::signal< void, TcpConnection * > | sslConnectionReady |
A signal that is emitted when the SSL connection is ready. | |
![]() | |
sigc::signal< void > | connected |
A signal that is emitted when a connection has been established. | |
![]() | |
static const int | DEFAULT_RECV_BUF_LEN = 1024 |
The default size of the reception buffer. | |
A class for creating a TCP client connection.
This class is used to create a TCP client connection. All details of how to create the connection is hidden inside the class. This make it very easy to create and use the connections. An example usage is shown below.
Definition at line 131 of file AsyncTcpClient.h.
|
inlineexplicit |
Constructor.
recv_buf_len | The length of the receiver buffer to use |
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.
Definition at line 144 of file AsyncTcpClient.h.
|
inline |
Constructor.
remote_host | The hostname of the remote host |
remote_port | The port on the remote host to connect to |
recv_buf_len | The length of the receiver buffer to use |
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.
Definition at line 159 of file AsyncTcpClient.h.
|
inline |
Constructor.
remote_ip | The IP address of the remote host |
remote_port | The port on the remote host to connect to |
recv_buf_len | The length of the receiver buffer to use |
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.
Definition at line 175 of file AsyncTcpClient.h.
|
inline |
Destructor.
Definition at line 184 of file AsyncTcpClient.h.
|
inlineoverrideprotectedvirtual |
Disconnect from the remote peer.
This function is used internally to close the connection to the remote peer.
Reimplemented from Async::TcpConnection.
Definition at line 218 of file AsyncTcpClient.h.
References Async::TcpClientBase::closeConnection().
Referenced by Async::TcpClient< ConT >::disconnect().
|
inlineoverridevirtual |
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
Reimplemented from Async::TcpConnection.
Definition at line 193 of file AsyncTcpClient.h.
References Async::TcpClient< ConT >::closeConnection().
|
inline |
Check if the connection is idle.
A connection being idle means that it is not connected nor connecting.
Definition at line 201 of file AsyncTcpClient.h.
References Async::TcpClientBase::isIdle().
|
protectedvirtual |
Move assignmnt operator.
other | The object to move from |
Reimplemented from Async::TcpClientBase.
|
inline |
Definition at line 206 of file AsyncTcpClient.h.