CppServer
1.0.4.0
C++ Server Library
|
SSL client. More...
#include <ssl_client.h>
Public Member Functions | |
SSLClient (const std::shared_ptr< Service > &service, const std::shared_ptr< SSLContext > &context, const std::string &address, int port) | |
Initialize SSL client with a given Asio service, SSL context, server address and port number. More... | |
SSLClient (const std::shared_ptr< Service > &service, const std::shared_ptr< SSLContext > &context, const std::string &address, const std::string &scheme) | |
Initialize SSL client with a given Asio service, SSL context, server address and scheme name. More... | |
SSLClient (const std::shared_ptr< Service > &service, const std::shared_ptr< SSLContext > &context, const asio::ip::tcp::endpoint &endpoint) | |
Initialize SSL client with a given Asio service, SSL context and endpoint. More... | |
SSLClient (const SSLClient &)=delete | |
SSLClient (SSLClient &&client)=delete | |
virtual | ~SSLClient () |
SSLClient & | operator= (const SSLClient &)=delete |
SSLClient & | operator= (SSLClient &&client)=delete |
const CppCommon::UUID & | id () const noexcept |
Get the client Id. More... | |
std::shared_ptr< Service > & | service () noexcept |
Get the Asio service. More... | |
std::shared_ptr< asio::io_service > & | io_service () noexcept |
Get the Asio IO service. More... | |
asio::io_service::strand & | strand () noexcept |
Get the Asio service strand for serialized handler execution. More... | |
std::shared_ptr< SSLContext > & | context () noexcept |
Get the client SSL context. More... | |
asio::ip::tcp::endpoint & | endpoint () noexcept |
Get the client endpoint. More... | |
asio::ssl::stream< asio::ip::tcp::socket > & | stream () noexcept |
Get the client SSL stream. More... | |
asio::ssl::stream< asio::ip::tcp::socket >::next_layer_type & | socket () noexcept |
Get the client socket. More... | |
const std::string & | address () const noexcept |
Get the server address. More... | |
const std::string & | scheme () const noexcept |
Get the scheme name. More... | |
int | port () const noexcept |
Get the server port number. More... | |
uint64_t | bytes_pending () const noexcept |
Get the number of bytes pending sent by the client. More... | |
uint64_t | bytes_sent () const noexcept |
Get the number of bytes sent by the client. More... | |
uint64_t | bytes_received () const noexcept |
Get the number of bytes received by the client. More... | |
bool | option_keep_alive () const noexcept |
Get the option: keep alive. More... | |
bool | option_no_delay () const noexcept |
Get the option: no delay. More... | |
size_t | option_receive_buffer_limit () const |
Get the option: receive buffer limit. More... | |
size_t | option_receive_buffer_size () const |
Get the option: receive buffer size. More... | |
size_t | option_send_buffer_limit () const |
Get the option: send buffer limit. More... | |
size_t | option_send_buffer_size () const |
Get the option: send buffer size. More... | |
bool | IsConnected () const noexcept |
Is the client connected? More... | |
bool | IsHandshaked () const noexcept |
Is the session handshaked? More... | |
virtual bool | Connect () |
Connect the client (synchronous) More... | |
virtual bool | Connect (const std::shared_ptr< TCPResolver > &resolver) |
Connect the client using the given DNS resolver (synchronous) More... | |
virtual bool | Disconnect () |
Disconnect the client (synchronous) More... | |
virtual bool | Reconnect () |
Reconnect the client (synchronous) More... | |
virtual bool | ConnectAsync () |
Connect the client (asynchronous) More... | |
virtual bool | ConnectAsync (const std::shared_ptr< TCPResolver > &resolver) |
Connect the client using the given DNS resolver (asynchronous) More... | |
virtual bool | DisconnectAsync () |
Disconnect the client (asynchronous) More... | |
virtual bool | ReconnectAsync () |
Reconnect the client (asynchronous) More... | |
virtual size_t | Send (const void *buffer, size_t size) |
Send data to the server (synchronous) More... | |
virtual size_t | Send (std::string_view text) |
Send text to the server (synchronous) More... | |
virtual size_t | Send (const void *buffer, size_t size, const CppCommon::Timespan &timeout) |
Send data to the server with timeout (synchronous) More... | |
virtual size_t | Send (std::string_view text, const CppCommon::Timespan &timeout) |
Send text to the server with timeout (synchronous) More... | |
virtual bool | SendAsync (const void *buffer, size_t size) |
Send data to the server (asynchronous) More... | |
virtual bool | SendAsync (std::string_view text) |
Send text to the server (asynchronous) More... | |
virtual size_t | Receive (void *buffer, size_t size) |
Receive data from the server (synchronous) More... | |
virtual std::string | Receive (size_t size) |
Receive text from the server (synchronous) More... | |
virtual size_t | Receive (void *buffer, size_t size, const CppCommon::Timespan &timeout) |
Receive data from the server with timeout (synchronous) More... | |
virtual std::string | Receive (size_t size, const CppCommon::Timespan &timeout) |
Receive text from the server with timeout (synchronous) More... | |
virtual void | ReceiveAsync () |
Receive data from the server (asynchronous) More... | |
void | SetupKeepAlive (bool enable) noexcept |
Setup option: keep alive. More... | |
void | SetupNoDelay (bool enable) noexcept |
Setup option: no delay. More... | |
void | SetupReceiveBufferLimit (size_t limit) |
Setup option: receive buffer limit. More... | |
void | SetupReceiveBufferSize (size_t size) |
Setup option: receive buffer size. More... | |
void | SetupSendBufferLimit (size_t limit) |
Setup option: send buffer limit. More... | |
void | SetupSendBufferSize (size_t size) |
Setup option: send buffer size. More... | |
Protected Member Functions | |
virtual void | onConnected () |
Handle client connected notification. More... | |
virtual void | onHandshaked () |
Handle session handshaked notification. More... | |
virtual void | onDisconnected () |
Handle client disconnected notification. More... | |
virtual void | onReceived (const void *buffer, size_t size) |
Handle buffer received notification. More... | |
virtual void | onSent (size_t sent, size_t pending) |
Handle buffer sent notification. More... | |
virtual void | onEmpty () |
Handle empty send buffer notification. More... | |
virtual void | onError (int error, const std::string &category, const std::string &message) |
Handle error notification. More... | |
SSL client.
SSL client is used to read/write data from/into the connected SSL server.
Thread-safe.
Definition at line 30 of file ssl_client.h.
CppServer::Asio::SSLClient::SSLClient | ( | const std::shared_ptr< Service > & | service, |
const std::shared_ptr< SSLContext > & | context, | ||
const std::string & | address, | ||
int | port | ||
) |
Initialize SSL client with a given Asio service, SSL context, server address and port number.
service | - Asio service |
context | - SSL context |
address | - Server address |
port | - Server port number |
Definition at line 14 of file ssl_client.cpp.
CppServer::Asio::SSLClient::SSLClient | ( | const std::shared_ptr< Service > & | service, |
const std::shared_ptr< SSLContext > & | context, | ||
const std::string & | address, | ||
const std::string & | scheme | ||
) |
Initialize SSL client with a given Asio service, SSL context, server address and scheme name.
service | - Asio service |
context | - SSL context |
address | - Server address |
scheme | - Scheme name |
Definition at line 48 of file ssl_client.cpp.
CppServer::Asio::SSLClient::SSLClient | ( | const std::shared_ptr< Service > & | service, |
const std::shared_ptr< SSLContext > & | context, | ||
const asio::ip::tcp::endpoint & | endpoint | ||
) |
Initialize SSL client with a given Asio service, SSL context and endpoint.
service | - Asio service |
context | - SSL context |
endpoint | - Server SSL endpoint |
Definition at line 83 of file ssl_client.cpp.
|
delete |
|
delete |
|
virtual |
Definition at line 118 of file ssl_client.cpp.
|
inlinenoexcept |
Get the server address.
Definition at line 82 of file ssl_client.h.
|
inlinenoexcept |
Get the number of bytes pending sent by the client.
Definition at line 89 of file ssl_client.h.
|
inlinenoexcept |
Get the number of bytes received by the client.
Definition at line 93 of file ssl_client.h.
|
inlinenoexcept |
Get the number of bytes sent by the client.
Definition at line 91 of file ssl_client.h.
|
virtual |
Connect the client (synchronous)
Please note that synchronous connect will not receive data automatically! You should use Receive() or ReceiveAsync() method manually after successful connection.
Reimplemented in CppServer::WS::WSSClient.
Definition at line 148 of file ssl_client.cpp.
|
virtual |
Connect the client using the given DNS resolver (synchronous)
Please note that synchronous connect will not receive data automatically! You should use Receive() or ReceiveAsync() method manually after successful connection.
resolver | - DNS resolver |
Definition at line 224 of file ssl_client.cpp.
|
virtual |
Connect the client (asynchronous)
Reimplemented in CppServer::WS::WSSClient.
Definition at line 352 of file ssl_client.cpp.
|
virtual |
Connect the client using the given DNS resolver (asynchronous)
resolver | - DNS resolver |
Definition at line 464 of file ssl_client.cpp.
|
inlinenoexcept |
Get the client SSL context.
Definition at line 73 of file ssl_client.h.
|
inlinevirtual |
Disconnect the client (synchronous)
Definition at line 134 of file ssl_client.h.
|
inlinevirtual |
Disconnect the client (asynchronous)
Definition at line 156 of file ssl_client.h.
|
inlinenoexcept |
Get the client endpoint.
Definition at line 75 of file ssl_client.h.
|
inlinenoexcept |
Get the client Id.
Definition at line 64 of file ssl_client.h.
|
inlinenoexcept |
Get the Asio IO service.
Definition at line 69 of file ssl_client.h.
|
inlinenoexcept |
Is the client connected?
Definition at line 109 of file ssl_client.h.
|
inlinenoexcept |
Is the session handshaked?
Definition at line 111 of file ssl_client.h.
|
inlineprotectedvirtual |
Handle client connected notification.
Definition at line 289 of file ssl_client.h.
|
inlineprotectedvirtual |
Handle client disconnected notification.
Reimplemented in CppServer::WS::WSSClient, CppServer::HTTP::HTTPSClientEx, and CppServer::HTTP::HTTPSClient.
Definition at line 293 of file ssl_client.h.
|
inlineprotectedvirtual |
Handle empty send buffer notification.
Notification is called when the send buffer is empty and ready for a new data to send.
This handler could be used to send another buffer to the server.
Definition at line 324 of file ssl_client.h.
|
inlineprotectedvirtual |
Handle error notification.
error | - Error code |
category | - Error category |
message | - Error message |
Definition at line 332 of file ssl_client.h.
|
inlineprotectedvirtual |
Handle session handshaked notification.
Reimplemented in CppServer::WS::WSSClient, and CppServer::HTTP::HTTPSClientEx.
Definition at line 291 of file ssl_client.h.
|
inlineprotectedvirtual |
Handle buffer received notification.
Notification is called when another part of buffer was received from the server.
buffer | - Received buffer |
size | - Received buffer size |
Reimplemented in CppServer::WS::WSSClient, and CppServer::HTTP::HTTPSClient.
Definition at line 303 of file ssl_client.h.
|
inlineprotectedvirtual |
Handle buffer sent notification.
Notification is called when another part of buffer was sent to the server.
This handler could be used to send another buffer to the server for instance when the pending size is zero.
sent | - Size of sent buffer |
pending | - Size of pending buffer |
Definition at line 315 of file ssl_client.h.
|
inlinenoexcept |
Get the option: keep alive.
Definition at line 96 of file ssl_client.h.
|
inlinenoexcept |
Get the option: no delay.
Definition at line 98 of file ssl_client.h.
|
inline |
Get the option: receive buffer limit.
Definition at line 100 of file ssl_client.h.
size_t CppServer::Asio::SSLClient::option_receive_buffer_size | ( | ) | const |
Get the option: receive buffer size.
Definition at line 122 of file ssl_client.cpp.
|
inline |
Get the option: send buffer limit.
Definition at line 104 of file ssl_client.h.
size_t CppServer::Asio::SSLClient::option_send_buffer_size | ( | ) | const |
Get the option: send buffer size.
Definition at line 129 of file ssl_client.cpp.
|
inlinenoexcept |
Get the server port number.
Definition at line 86 of file ssl_client.h.
|
virtual |
Receive text from the server (synchronous)
size | - Text size to receive |
Definition at line 840 of file ssl_client.cpp.
|
virtual |
Receive text from the server with timeout (synchronous)
size | - Text size to receive |
timeout | - Timeout |
Definition at line 910 of file ssl_client.cpp.
|
virtual |
Receive data from the server (synchronous)
buffer | - Buffer to receive |
size | - Buffer size to receive |
Definition at line 805 of file ssl_client.cpp.
|
virtual |
Receive data from the server with timeout (synchronous)
buffer | - Buffer to receive |
size | - Buffer size to receive |
timeout | - Timeout |
Definition at line 847 of file ssl_client.cpp.
|
virtual |
Receive data from the server (asynchronous)
Definition at line 917 of file ssl_client.cpp.
|
virtual |
Reconnect the client (synchronous)
Definition at line 344 of file ssl_client.cpp.
|
virtual |
Reconnect the client (asynchronous)
Definition at line 644 of file ssl_client.cpp.
|
inlinenoexcept |
Get the scheme name.
Definition at line 84 of file ssl_client.h.
|
virtual |
Send data to the server (synchronous)
buffer | - Buffer to send |
size | - Buffer size |
Definition at line 655 of file ssl_client.cpp.
|
virtual |
Send data to the server with timeout (synchronous)
buffer | - Buffer to send |
size | - Buffer size |
timeout | - Timeout |
Definition at line 690 of file ssl_client.cpp.
|
inlinevirtual |
Send text to the server (synchronous)
text | - Text to send |
Definition at line 175 of file ssl_client.h.
|
inlinevirtual |
Send text to the server with timeout (synchronous)
text | - Text to send |
timeout | - Timeout |
Definition at line 191 of file ssl_client.h.
|
virtual |
Send data to the server (asynchronous)
buffer | - Buffer to send |
size | - Buffer size |
Definition at line 753 of file ssl_client.cpp.
|
inlinevirtual |
Send text to the server (asynchronous)
text | - Text to send |
Definition at line 205 of file ssl_client.h.
|
inlinenoexcept |
Get the Asio service.
Definition at line 67 of file ssl_client.h.
|
inlinenoexcept |
Setup option: keep alive.
This option will setup SO_KEEPALIVE if the OS support this feature.
enable | - Enable/disable option |
Definition at line 246 of file ssl_client.h.
|
inlinenoexcept |
Setup option: no delay.
This option will enable/disable Nagle's algorithm for TCP protocol.
https://en.wikipedia.org/wiki/Nagle%27s_algorithm
enable | - Enable/disable option |
Definition at line 255 of file ssl_client.h.
|
inline |
Setup option: receive buffer limit.
The client will be disconnected if the receive buffer limit is met. Default is unlimited.
limit | - Receive buffer limit |
Definition at line 263 of file ssl_client.h.
void CppServer::Asio::SSLClient::SetupReceiveBufferSize | ( | size_t | size | ) |
Setup option: receive buffer size.
This option will setup SO_RCVBUF if the OS support this feature.
size | - Receive buffer size |
Definition at line 136 of file ssl_client.cpp.
|
inline |
Setup option: send buffer limit.
The client will be disconnected if the send buffer limit is met. Default is unlimited.
limit | - Send buffer limit |
Definition at line 278 of file ssl_client.h.
void CppServer::Asio::SSLClient::SetupSendBufferSize | ( | size_t | size | ) |
Setup option: send buffer size.
This option will setup SO_SNDBUF if the OS support this feature.
size | - Send buffer size |
Definition at line 142 of file ssl_client.cpp.
|
inlinenoexcept |
Get the client socket.
Definition at line 79 of file ssl_client.h.
|
inlinenoexcept |
Get the Asio service strand for serialized handler execution.
Definition at line 71 of file ssl_client.h.
|
inlinenoexcept |
Get the client SSL stream.
Definition at line 77 of file ssl_client.h.