This class represents a TCP client.
More...
#include <trantor/net/TcpClient.h>
|
| | TcpClient (EventLoop *loop, const InetAddress &serverAddr, const std::string &nameArg) |
| | Construct a new TCP client instance.
|
|
void | connect () |
| | Connect to the server.
|
|
void | disconnect () |
| | Disconnect from the server.
|
|
void | stop () |
| | Stop connecting to the server.
|
| TcpConnectionPtr | connection () const |
| | Get the TCP connection to the server.
|
| EventLoop * | getLoop () const |
| | Get the event loop.
|
| bool | retry () const |
| | Check whether the client re-connect to the server.
|
|
void | enableRetry () |
| | Enable retrying.
|
| const std::string & | name () const |
| | Get the name of the client.
|
| void | setConnectionCallback (const ConnectionCallback &cb) |
| | Set the connection callback.
|
|
void | setConnectionCallback (ConnectionCallback &&cb) |
| void | setConnectionErrorCallback (const ConnectionErrorCallback &cb) |
| | Set the connection error callback.
|
| void | setMessageCallback (const RecvMessageCallback &cb) |
| | Set the message callback.
|
|
void | setMessageCallback (RecvMessageCallback &&cb) |
| void | setWriteCompleteCallback (const WriteCompleteCallback &cb) |
| | Set the write complete callback.
|
|
void | setWriteCompleteCallback (WriteCompleteCallback &&cb) |
| void | setSSLErrorCallback (const SSLErrorCallback &cb) |
| | Set the callback for errors of SSL.
|
|
void | setSSLErrorCallback (SSLErrorCallback &&cb) |
| void | setSockOptCallback (const SockOptCallback &cb) |
| | Set the callback for set socket option.
|
|
void | setSockOptCallback (SockOptCallback &&cb) |
| void | enableSSL (bool useOldTLS=false, bool validateCert=true, std::string hostname="", const std::vector< std::pair< std::string, std::string > > &sslConfCmds={}, const std::string &certPath="", const std::string &keyPath="", const std::string &caPath="") |
| | Enable SSL encryption.
|
|
void | enableSSL (TLSPolicyPtr policy) |
| | Enable SSL encryption.
|
This class represents a TCP client.
◆ TcpClient()
| trantor::TcpClient::TcpClient |
( |
EventLoop * | loop, |
|
|
const InetAddress & | serverAddr, |
|
|
const std::string & | nameArg ) |
Construct a new TCP client instance.
- Parameters
-
| loop | The event loop in which the client runs. |
| serverAddr | The address of the server. |
| nameArg | The name of the client. |
◆ connection()
| TcpConnectionPtr trantor::TcpClient::connection |
( |
| ) |
const |
|
inline |
Get the TCP connection to the server.
- Returns
- TcpConnectionPtr
◆ enableSSL()
| void trantor::TcpClient::enableSSL |
( |
bool | useOldTLS = false, |
|
|
bool | validateCert = true, |
|
|
std::string | hostname = "", |
|
|
const std::vector< std::pair< std::string, std::string > > & | sslConfCmds = {}, |
|
|
const std::string & | certPath = "", |
|
|
const std::string & | keyPath = "", |
|
|
const std::string & | caPath = "" ) |
Enable SSL encryption.
- Parameters
-
| useOldTLS | If true, the TLS 1.0 and 1.1 are supported by the client. |
| validateCert | If true, we try to validate if the peer's SSL cert is valid. |
| hostname | The server hostname for SNI. If it is empty, the SNI is not used. |
| sslConfCmds | The commands used to call the SSL_CONF_cmd function in OpenSSL. |
| certPath | The path of the certificate file. |
| keyPath | The path of the private key file. |
| caPath | The path of the certificate authority file. |
- Note
- It's well known that TLS 1.0 and 1.1 are not considered secure in
- And it's a good practice to only use TLS 1.2 and above.
◆ getLoop()
| EventLoop * trantor::TcpClient::getLoop |
( |
| ) |
const |
|
inline |
Get the event loop.
- Returns
- EventLoop*
◆ name()
| const std::string & trantor::TcpClient::name |
( |
| ) |
const |
|
inline |
Get the name of the client.
- Returns
- const std::string&
◆ retry()
| bool trantor::TcpClient::retry |
( |
| ) |
const |
|
inline |
Check whether the client re-connect to the server.
- Returns
- true
-
false
◆ setConnectionCallback()
| void trantor::TcpClient::setConnectionCallback |
( |
const ConnectionCallback & | cb | ) |
|
|
inline |
Set the connection callback.
- Parameters
-
| cb | The callback is called when the connection to the server is established or closed. |
◆ setConnectionErrorCallback()
| void trantor::TcpClient::setConnectionErrorCallback |
( |
const ConnectionErrorCallback & | cb | ) |
|
|
inline |
Set the connection error callback.
- Parameters
-
| cb | The callback is called when an error occurs during connecting to the server. |
◆ setMessageCallback()
| void trantor::TcpClient::setMessageCallback |
( |
const RecvMessageCallback & | cb | ) |
|
|
inline |
Set the message callback.
- Parameters
-
| cb | The callback is called when some data is received from the server. |
◆ setSockOptCallback()
| void trantor::TcpClient::setSockOptCallback |
( |
const SockOptCallback & | cb | ) |
|
Set the callback for set socket option.
- Parameters
-
| cb | The callback is called, before connect |
◆ setSSLErrorCallback()
| void trantor::TcpClient::setSSLErrorCallback |
( |
const SSLErrorCallback & | cb | ) |
|
|
inline |
Set the callback for errors of SSL.
- Parameters
-
| cb | The callback is called when an SSL error occurs. |
◆ setWriteCompleteCallback()
| void trantor::TcpClient::setWriteCompleteCallback |
( |
const WriteCompleteCallback & | cb | ) |
|
|
inline |
Set the write complete callback.
Set write complete callback. Not thread safe.
- Parameters
-
| cb | The callback is called when data to send is written to the socket. |
The documentation for this class was generated from the following file: