CppServer  1.0.4.0
C++ Server Library
Public Member Functions | Protected Member Functions | List of all members
CppServer::Asio::SSLClient Class Reference

SSL client. More...

#include <ssl_client.h>

Inheritance diagram for CppServer::Asio::SSLClient:
CppServer::HTTP::HTTPSClient CppServer::HTTP::HTTPSClientEx CppServer::WS::WSSClient

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 ()
 
SSLClientoperator= (const SSLClient &)=delete
 
SSLClientoperator= (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...
 

Detailed Description

SSL client.

SSL client is used to read/write data from/into the connected SSL server.

Thread-safe.

Examples
ssl_chat_client.cpp.

Definition at line 30 of file ssl_client.h.

Constructor & Destructor Documentation

◆ SSLClient() [1/5]

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.

Parameters
service- Asio service
context- SSL context
address- Server address
port- Server port number
Examples
ssl_chat_client.cpp.

Definition at line 14 of file ssl_client.cpp.

◆ SSLClient() [2/5]

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.

Parameters
service- Asio service
context- SSL context
address- Server address
scheme- Scheme name

Definition at line 48 of file ssl_client.cpp.

◆ SSLClient() [3/5]

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.

Parameters
service- Asio service
context- SSL context
endpoint- Server SSL endpoint

Definition at line 83 of file ssl_client.cpp.

◆ SSLClient() [4/5]

CppServer::Asio::SSLClient::SSLClient ( const SSLClient )
delete

◆ SSLClient() [5/5]

CppServer::Asio::SSLClient::SSLClient ( SSLClient &&  client)
delete

◆ ~SSLClient()

CppServer::Asio::SSLClient::~SSLClient ( )
virtual

Definition at line 118 of file ssl_client.cpp.

Member Function Documentation

◆ address()

const std::string& CppServer::Asio::SSLClient::address ( ) const
inlinenoexcept

Get the server address.

Definition at line 82 of file ssl_client.h.

◆ bytes_pending()

uint64_t CppServer::Asio::SSLClient::bytes_pending ( ) const
inlinenoexcept

Get the number of bytes pending sent by the client.

Definition at line 89 of file ssl_client.h.

◆ bytes_received()

uint64_t CppServer::Asio::SSLClient::bytes_received ( ) const
inlinenoexcept

Get the number of bytes received by the client.

Definition at line 93 of file ssl_client.h.

◆ bytes_sent()

uint64_t CppServer::Asio::SSLClient::bytes_sent ( ) const
inlinenoexcept

Get the number of bytes sent by the client.

Definition at line 91 of file ssl_client.h.

◆ Connect() [1/2]

bool CppServer::Asio::SSLClient::Connect ( )
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.

Returns
'true' if the client was successfully connected, 'false' if the client failed to connect

Reimplemented in CppServer::WS::WSSClient.

Definition at line 148 of file ssl_client.cpp.

◆ Connect() [2/2]

bool CppServer::Asio::SSLClient::Connect ( const std::shared_ptr< TCPResolver > &  resolver)
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.

Parameters
resolver- DNS resolver
Returns
'true' if the client was successfully connected, 'false' if the client failed to connect

Definition at line 224 of file ssl_client.cpp.

◆ ConnectAsync() [1/2]

bool CppServer::Asio::SSLClient::ConnectAsync ( )
virtual

Connect the client (asynchronous)

Returns
'true' if the client was successfully connected, 'false' if the client failed to connect

Reimplemented in CppServer::WS::WSSClient.

Examples
ssl_chat_client.cpp.

Definition at line 352 of file ssl_client.cpp.

◆ ConnectAsync() [2/2]

bool CppServer::Asio::SSLClient::ConnectAsync ( const std::shared_ptr< TCPResolver > &  resolver)
virtual

Connect the client using the given DNS resolver (asynchronous)

Parameters
resolver- DNS resolver
Returns
'true' if the client was successfully connected, 'false' if the client failed to connect

Definition at line 464 of file ssl_client.cpp.

◆ context()

std::shared_ptr<SSLContext>& CppServer::Asio::SSLClient::context ( )
inlinenoexcept

Get the client SSL context.

Definition at line 73 of file ssl_client.h.

◆ Disconnect()

virtual bool CppServer::Asio::SSLClient::Disconnect ( )
inlinevirtual

Disconnect the client (synchronous)

Returns
'true' if the client was successfully disconnected, 'false' if the client is already disconnected

Definition at line 134 of file ssl_client.h.

◆ DisconnectAsync()

virtual bool CppServer::Asio::SSLClient::DisconnectAsync ( )
inlinevirtual

Disconnect the client (asynchronous)

Returns
'true' if the client was successfully disconnected, 'false' if the client is already disconnected
Examples
ssl_chat_client.cpp.

Definition at line 156 of file ssl_client.h.

◆ endpoint()

asio::ip::tcp::endpoint& CppServer::Asio::SSLClient::endpoint ( )
inlinenoexcept

Get the client endpoint.

Definition at line 75 of file ssl_client.h.

◆ id()

const CppCommon::UUID& CppServer::Asio::SSLClient::id ( ) const
inlinenoexcept

Get the client Id.

Examples
ssl_chat_client.cpp, and wss_chat_client.cpp.

Definition at line 64 of file ssl_client.h.

◆ io_service()

std::shared_ptr<asio::io_service>& CppServer::Asio::SSLClient::io_service ( )
inlinenoexcept

Get the Asio IO service.

Definition at line 69 of file ssl_client.h.

◆ IsConnected()

bool CppServer::Asio::SSLClient::IsConnected ( ) const
inlinenoexcept

Is the client connected?

Examples
ssl_chat_client.cpp, and wss_chat_client.cpp.

Definition at line 109 of file ssl_client.h.

◆ IsHandshaked()

bool CppServer::Asio::SSLClient::IsHandshaked ( ) const
inlinenoexcept

Is the session handshaked?

Definition at line 111 of file ssl_client.h.

◆ onConnected()

virtual void CppServer::Asio::SSLClient::onConnected ( )
inlineprotectedvirtual

Handle client connected notification.

Examples
ssl_chat_client.cpp.

Definition at line 289 of file ssl_client.h.

◆ onDisconnected()

virtual void CppServer::Asio::SSLClient::onDisconnected ( )
inlineprotectedvirtual

Handle client disconnected notification.

Reimplemented in CppServer::WS::WSSClient, CppServer::HTTP::HTTPSClientEx, and CppServer::HTTP::HTTPSClient.

Examples
ssl_chat_client.cpp.

Definition at line 293 of file ssl_client.h.

◆ onEmpty()

virtual void CppServer::Asio::SSLClient::onEmpty ( )
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.

◆ onError()

virtual void CppServer::Asio::SSLClient::onError ( int  error,
const std::string &  category,
const std::string &  message 
)
inlineprotectedvirtual

Handle error notification.

Parameters
error- Error code
category- Error category
message- Error message
Examples
ssl_chat_client.cpp, and wss_chat_client.cpp.

Definition at line 332 of file ssl_client.h.

◆ onHandshaked()

virtual void CppServer::Asio::SSLClient::onHandshaked ( )
inlineprotectedvirtual

Handle session handshaked notification.

Reimplemented in CppServer::WS::WSSClient, and CppServer::HTTP::HTTPSClientEx.

Examples
ssl_chat_client.cpp.

Definition at line 291 of file ssl_client.h.

◆ onReceived()

virtual void CppServer::Asio::SSLClient::onReceived ( const void *  buffer,
size_t  size 
)
inlineprotectedvirtual

Handle buffer received notification.

Notification is called when another part of buffer was received from the server.

Parameters
buffer- Received buffer
size- Received buffer size

Reimplemented in CppServer::WS::WSSClient, and CppServer::HTTP::HTTPSClient.

Examples
ssl_chat_client.cpp.

Definition at line 303 of file ssl_client.h.

◆ onSent()

virtual void CppServer::Asio::SSLClient::onSent ( size_t  sent,
size_t  pending 
)
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.

Parameters
sent- Size of sent buffer
pending- Size of pending buffer

Definition at line 315 of file ssl_client.h.

◆ operator=() [1/2]

SSLClient& CppServer::Asio::SSLClient::operator= ( const SSLClient )
delete

◆ operator=() [2/2]

SSLClient& CppServer::Asio::SSLClient::operator= ( SSLClient &&  client)
delete

◆ option_keep_alive()

bool CppServer::Asio::SSLClient::option_keep_alive ( ) const
inlinenoexcept

Get the option: keep alive.

Definition at line 96 of file ssl_client.h.

◆ option_no_delay()

bool CppServer::Asio::SSLClient::option_no_delay ( ) const
inlinenoexcept

Get the option: no delay.

Definition at line 98 of file ssl_client.h.

◆ option_receive_buffer_limit()

size_t CppServer::Asio::SSLClient::option_receive_buffer_limit ( ) const
inline

Get the option: receive buffer limit.

Definition at line 100 of file ssl_client.h.

◆ option_receive_buffer_size()

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.

◆ option_send_buffer_limit()

size_t CppServer::Asio::SSLClient::option_send_buffer_limit ( ) const
inline

Get the option: send buffer limit.

Definition at line 104 of file ssl_client.h.

◆ option_send_buffer_size()

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.

◆ port()

int CppServer::Asio::SSLClient::port ( ) const
inlinenoexcept

Get the server port number.

Definition at line 86 of file ssl_client.h.

◆ Receive() [1/4]

std::string CppServer::Asio::SSLClient::Receive ( size_t  size)
virtual

Receive text from the server (synchronous)

Parameters
size- Text size to receive
Returns
Received text

Definition at line 840 of file ssl_client.cpp.

◆ Receive() [2/4]

std::string CppServer::Asio::SSLClient::Receive ( size_t  size,
const CppCommon::Timespan &  timeout 
)
virtual

Receive text from the server with timeout (synchronous)

Parameters
size- Text size to receive
timeout- Timeout
Returns
Received text

Definition at line 910 of file ssl_client.cpp.

◆ Receive() [3/4]

size_t CppServer::Asio::SSLClient::Receive ( void *  buffer,
size_t  size 
)
virtual

Receive data from the server (synchronous)

Parameters
buffer- Buffer to receive
size- Buffer size to receive
Returns
Size of received data

Definition at line 805 of file ssl_client.cpp.

◆ Receive() [4/4]

size_t CppServer::Asio::SSLClient::Receive ( void *  buffer,
size_t  size,
const CppCommon::Timespan &  timeout 
)
virtual

Receive data from the server with timeout (synchronous)

Parameters
buffer- Buffer to receive
size- Buffer size to receive
timeout- Timeout
Returns
Size of received data

Definition at line 847 of file ssl_client.cpp.

◆ ReceiveAsync()

void CppServer::Asio::SSLClient::ReceiveAsync ( )
virtual

Receive data from the server (asynchronous)

Definition at line 917 of file ssl_client.cpp.

◆ Reconnect()

bool CppServer::Asio::SSLClient::Reconnect ( )
virtual

Reconnect the client (synchronous)

Returns
'true' if the client was successfully reconnected, 'false' if the client is already reconnected

Definition at line 344 of file ssl_client.cpp.

◆ ReconnectAsync()

bool CppServer::Asio::SSLClient::ReconnectAsync ( )
virtual

Reconnect the client (asynchronous)

Returns
'true' if the client was successfully reconnected, 'false' if the client is already reconnected

Definition at line 644 of file ssl_client.cpp.

◆ scheme()

const std::string& CppServer::Asio::SSLClient::scheme ( ) const
inlinenoexcept

Get the scheme name.

Definition at line 84 of file ssl_client.h.

◆ Send() [1/4]

size_t CppServer::Asio::SSLClient::Send ( const void *  buffer,
size_t  size 
)
virtual

Send data to the server (synchronous)

Parameters
buffer- Buffer to send
size- Buffer size
Returns
Size of sent data

Definition at line 655 of file ssl_client.cpp.

◆ Send() [2/4]

size_t CppServer::Asio::SSLClient::Send ( const void *  buffer,
size_t  size,
const CppCommon::Timespan &  timeout 
)
virtual

Send data to the server with timeout (synchronous)

Parameters
buffer- Buffer to send
size- Buffer size
timeout- Timeout
Returns
Size of sent data

Definition at line 690 of file ssl_client.cpp.

◆ Send() [3/4]

virtual size_t CppServer::Asio::SSLClient::Send ( std::string_view  text)
inlinevirtual

Send text to the server (synchronous)

Parameters
text- Text to send
Returns
Size of sent text

Definition at line 175 of file ssl_client.h.

◆ Send() [4/4]

virtual size_t CppServer::Asio::SSLClient::Send ( std::string_view  text,
const CppCommon::Timespan &  timeout 
)
inlinevirtual

Send text to the server with timeout (synchronous)

Parameters
text- Text to send
timeout- Timeout
Returns
Size of sent text

Definition at line 191 of file ssl_client.h.

◆ SendAsync() [1/2]

bool CppServer::Asio::SSLClient::SendAsync ( const void *  buffer,
size_t  size 
)
virtual

Send data to the server (asynchronous)

Parameters
buffer- Buffer to send
size- Buffer size
Returns
'true' if the data was successfully sent, 'false' if the client is not connected

Definition at line 753 of file ssl_client.cpp.

◆ SendAsync() [2/2]

virtual bool CppServer::Asio::SSLClient::SendAsync ( std::string_view  text)
inlinevirtual

Send text to the server (asynchronous)

Parameters
text- Text to send
Returns
'true' if the text was successfully sent, 'false' if the client is not connected

Definition at line 205 of file ssl_client.h.

◆ service()

std::shared_ptr<Service>& CppServer::Asio::SSLClient::service ( )
inlinenoexcept

Get the Asio service.

Definition at line 67 of file ssl_client.h.

◆ SetupKeepAlive()

void CppServer::Asio::SSLClient::SetupKeepAlive ( bool  enable)
inlinenoexcept

Setup option: keep alive.

This option will setup SO_KEEPALIVE if the OS support this feature.

Parameters
enable- Enable/disable option

Definition at line 246 of file ssl_client.h.

◆ SetupNoDelay()

void CppServer::Asio::SSLClient::SetupNoDelay ( bool  enable)
inlinenoexcept

Setup option: no delay.

This option will enable/disable Nagle's algorithm for TCP protocol.

https://en.wikipedia.org/wiki/Nagle%27s_algorithm

Parameters
enable- Enable/disable option

Definition at line 255 of file ssl_client.h.

◆ SetupReceiveBufferLimit()

void CppServer::Asio::SSLClient::SetupReceiveBufferLimit ( size_t  limit)
inline

Setup option: receive buffer limit.

The client will be disconnected if the receive buffer limit is met. Default is unlimited.

Parameters
limit- Receive buffer limit

Definition at line 263 of file ssl_client.h.

◆ SetupReceiveBufferSize()

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.

Parameters
size- Receive buffer size

Definition at line 136 of file ssl_client.cpp.

◆ SetupSendBufferLimit()

void CppServer::Asio::SSLClient::SetupSendBufferLimit ( size_t  limit)
inline

Setup option: send buffer limit.

The client will be disconnected if the send buffer limit is met. Default is unlimited.

Parameters
limit- Send buffer limit

Definition at line 278 of file ssl_client.h.

◆ SetupSendBufferSize()

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.

Parameters
size- Send buffer size

Definition at line 142 of file ssl_client.cpp.

◆ socket()

asio::ssl::stream<asio::ip::tcp::socket>::next_layer_type& CppServer::Asio::SSLClient::socket ( )
inlinenoexcept

Get the client socket.

Definition at line 79 of file ssl_client.h.

◆ strand()

asio::io_service::strand& CppServer::Asio::SSLClient::strand ( )
inlinenoexcept

Get the Asio service strand for serialized handler execution.

Definition at line 71 of file ssl_client.h.

◆ stream()

asio::ssl::stream<asio::ip::tcp::socket>& CppServer::Asio::SSLClient::stream ( )
inlinenoexcept

Get the client SSL stream.

Definition at line 77 of file ssl_client.h.


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