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

SSL session. More...

#include <ssl_session.h>

Inheritance diagram for CppServer::Asio::SSLSession:
CppServer::HTTP::HTTPSSession CppServer::WS::WSSSession

Public Member Functions

 SSLSession (const std::shared_ptr< SSLServer > &server)
 Initialize the session with a given server. More...
 
 SSLSession (const SSLSession &)=delete
 
 SSLSession (SSLSession &&)=delete
 
virtual ~SSLSession ()=default
 
SSLSessionoperator= (const SSLSession &)=delete
 
SSLSessionoperator= (SSLSession &&)=delete
 
const CppCommon::UUID & id () const noexcept
 Get the session Id. More...
 
std::shared_ptr< SSLServer > & server () noexcept
 Get the server. 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...
 
asio::ssl::stream< asio::ip::tcp::socket > & stream () noexcept
 Get the session SSL stream. More...
 
asio::ssl::stream< asio::ip::tcp::socket >::next_layer_type & socket () noexcept
 Get the session socket. More...
 
uint64_t bytes_pending () const noexcept
 Get the number of bytes pending sent by the session. More...
 
uint64_t bytes_sent () const noexcept
 Get the number of bytes sent by the session. More...
 
uint64_t bytes_received () const noexcept
 Get the number of bytes received by the session. More...
 
size_t option_receive_buffer_limit () const noexcept
 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 noexcept
 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 session connected? More...
 
bool IsHandshaked () const noexcept
 Is the session handshaked? More...
 
virtual bool Disconnect ()
 Disconnect the session. More...
 
virtual size_t Send (const void *buffer, size_t size)
 Send data to the client (synchronous) More...
 
virtual size_t Send (std::string_view text)
 Send text to the client (synchronous) More...
 
virtual size_t Send (const void *buffer, size_t size, const CppCommon::Timespan &timeout)
 Send data to the client with timeout (synchronous) More...
 
virtual size_t Send (std::string_view text, const CppCommon::Timespan &timeout)
 Send text to the client with timeout (synchronous) More...
 
virtual bool SendAsync (const void *buffer, size_t size)
 Send data to the client (asynchronous) More...
 
virtual bool SendAsync (std::string_view text)
 Send text to the client (asynchronous) More...
 
virtual size_t Receive (void *buffer, size_t size)
 Receive data from the client (synchronous) More...
 
virtual std::string Receive (size_t size)
 Receive text from the client (synchronous) More...
 
virtual size_t Receive (void *buffer, size_t size, const CppCommon::Timespan &timeout)
 Receive data from the client with timeout (synchronous) More...
 
virtual std::string Receive (size_t size, const CppCommon::Timespan &timeout)
 Receive text from the client with timeout (synchronous) More...
 
virtual void ReceiveAsync ()
 Receive data from the client (asynchronous) More...
 
void SetupReceiveBufferLimit (size_t limit) noexcept
 Setup option: receive buffer limit. More...
 
void SetupReceiveBufferSize (size_t size)
 Setup option: receive buffer size. More...
 
void SetupSendBufferLimit (size_t limit) noexcept
 Setup option: send buffer limit. More...
 
void SetupSendBufferSize (size_t size)
 Setup option: send buffer size. More...
 

Protected Member Functions

virtual void onConnected ()
 Handle session connected notification. More...
 
virtual void onHandshaked ()
 Handle session handshaked notification. More...
 
virtual void onDisconnected ()
 Handle session 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...
 

Friends

class SSLServer
 

Detailed Description

SSL session.

SSL session is used to read and write data from the connected SSL client.

Thread-safe.

Examples
ssl_chat_server.cpp.

Definition at line 27 of file ssl_session.h.

Constructor & Destructor Documentation

◆ SSLSession() [1/3]

CppServer::Asio::SSLSession::SSLSession ( const std::shared_ptr< SSLServer > &  server)
explicit

Initialize the session with a given server.

Parameters
server- Connected server
Examples
ssl_chat_server.cpp.

Definition at line 15 of file ssl_session.cpp.

◆ SSLSession() [2/3]

CppServer::Asio::SSLSession::SSLSession ( const SSLSession )
delete

◆ SSLSession() [3/3]

CppServer::Asio::SSLSession::SSLSession ( SSLSession &&  )
delete

◆ ~SSLSession()

virtual CppServer::Asio::SSLSession::~SSLSession ( )
virtualdefault

Member Function Documentation

◆ bytes_pending()

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

Get the number of bytes pending sent by the session.

Definition at line 59 of file ssl_session.h.

◆ bytes_received()

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

Get the number of bytes received by the session.

Definition at line 63 of file ssl_session.h.

◆ bytes_sent()

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

Get the number of bytes sent by the session.

Definition at line 61 of file ssl_session.h.

◆ Disconnect()

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

Disconnect the session.

Returns
'true' if the section was successfully disconnected, 'false' if the section is already disconnected
Examples
ssl_chat_server.cpp.

Definition at line 83 of file ssl_session.h.

◆ id()

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

Get the session Id.

Examples
ssl_chat_server.cpp, and wss_chat_server.cpp.

Definition at line 45 of file ssl_session.h.

◆ io_service()

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

Get the Asio IO service.

Definition at line 50 of file ssl_session.h.

◆ IsConnected()

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

Is the session connected?

Definition at line 75 of file ssl_session.h.

◆ IsHandshaked()

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

Is the session handshaked?

Definition at line 77 of file ssl_session.h.

◆ onConnected()

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

Handle session connected notification.

Examples
ssl_chat_server.cpp.

Definition at line 195 of file ssl_session.h.

◆ onDisconnected()

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

Handle session disconnected notification.

Reimplemented in CppServer::WS::WSSSession, and CppServer::HTTP::HTTPSSession.

Examples
ssl_chat_server.cpp.

Definition at line 199 of file ssl_session.h.

◆ onEmpty()

virtual void CppServer::Asio::SSLSession::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 client.

Definition at line 230 of file ssl_session.h.

◆ onError()

virtual void CppServer::Asio::SSLSession::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
https_server.cpp, ssl_chat_server.cpp, and wss_chat_server.cpp.

Definition at line 238 of file ssl_session.h.

◆ onHandshaked()

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

Handle session handshaked notification.

Examples
ssl_chat_server.cpp.

Definition at line 197 of file ssl_session.h.

◆ onReceived()

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

Handle buffer received notification.

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

Parameters
buffer- Received buffer
size- Received buffer size

Reimplemented in CppServer::WS::WSSSession, and CppServer::HTTP::HTTPSSession.

Examples
ssl_chat_server.cpp.

Definition at line 209 of file ssl_session.h.

◆ onSent()

virtual void CppServer::Asio::SSLSession::onSent ( size_t  sent,
size_t  pending 
)
inlineprotectedvirtual

Handle buffer sent notification.

Notification is called when another part of buffer was sent to the client.

This handler could be used to send another buffer to the client for instance when the pending size is zero.

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

Definition at line 221 of file ssl_session.h.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

SSLSession& CppServer::Asio::SSLSession::operator= ( SSLSession &&  )
delete

◆ option_receive_buffer_limit()

size_t CppServer::Asio::SSLSession::option_receive_buffer_limit ( ) const
inlinenoexcept

Get the option: receive buffer limit.

Definition at line 66 of file ssl_session.h.

◆ option_receive_buffer_size()

size_t CppServer::Asio::SSLSession::option_receive_buffer_size ( ) const

Get the option: receive buffer size.

Definition at line 34 of file ssl_session.cpp.

◆ option_send_buffer_limit()

size_t CppServer::Asio::SSLSession::option_send_buffer_limit ( ) const
inlinenoexcept

Get the option: send buffer limit.

Definition at line 70 of file ssl_session.h.

◆ option_send_buffer_size()

size_t CppServer::Asio::SSLSession::option_send_buffer_size ( ) const

Get the option: send buffer size.

Definition at line 41 of file ssl_session.cpp.

◆ Receive() [1/4]

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

Receive text from the client (synchronous)

Parameters
size- Text size to receive
Returns
Received text

Definition at line 399 of file ssl_session.cpp.

◆ Receive() [2/4]

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

Receive text from the client with timeout (synchronous)

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

Definition at line 470 of file ssl_session.cpp.

◆ Receive() [3/4]

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

Receive data from the client (synchronous)

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

Definition at line 363 of file ssl_session.cpp.

◆ Receive() [4/4]

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

Receive data from the client with timeout (synchronous)

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

Definition at line 406 of file ssl_session.cpp.

◆ ReceiveAsync()

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

Receive data from the client (asynchronous)

Definition at line 477 of file ssl_session.cpp.

◆ Send() [1/4]

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

Send data to the client (synchronous)

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

Definition at line 211 of file ssl_session.cpp.

◆ Send() [2/4]

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

Send data to the client with timeout (synchronous)

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

Definition at line 247 of file ssl_session.cpp.

◆ Send() [3/4]

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

Send text to the client (synchronous)

Parameters
text- Text to send
Returns
Size of sent text

Definition at line 97 of file ssl_session.h.

◆ Send() [4/4]

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

Send text to the client with timeout (synchronous)

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

Definition at line 113 of file ssl_session.h.

◆ SendAsync() [1/2]

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

Send data to the client (asynchronous)

Parameters
buffer- Buffer to send
size- Buffer size
Returns
'true' if the data was successfully sent, 'false' if the session is not connected
Examples
ssl_chat_server.cpp.

Definition at line 311 of file ssl_session.cpp.

◆ SendAsync() [2/2]

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

Send text to the client (asynchronous)

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

Definition at line 127 of file ssl_session.h.

◆ server()

std::shared_ptr<SSLServer>& CppServer::Asio::SSLSession::server ( )
inlinenoexcept

Get the server.

Examples
ssl_chat_server.cpp, and wss_chat_server.cpp.

Definition at line 48 of file ssl_session.h.

◆ SetupReceiveBufferLimit()

void CppServer::Asio::SSLSession::SetupReceiveBufferLimit ( size_t  limit)
inlinenoexcept

Setup option: receive buffer limit.

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

Parameters
limit- Receive buffer limit

Definition at line 169 of file ssl_session.h.

◆ SetupReceiveBufferSize()

void CppServer::Asio::SSLSession::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 48 of file ssl_session.cpp.

◆ SetupSendBufferLimit()

void CppServer::Asio::SSLSession::SetupSendBufferLimit ( size_t  limit)
inlinenoexcept

Setup option: send buffer limit.

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

Parameters
limit- Send buffer limit

Definition at line 184 of file ssl_session.h.

◆ SetupSendBufferSize()

void CppServer::Asio::SSLSession::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 54 of file ssl_session.cpp.

◆ socket()

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

Get the session socket.

Definition at line 56 of file ssl_session.h.

◆ strand()

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

Get the Asio service strand for serialized handler execution.

Definition at line 52 of file ssl_session.h.

◆ stream()

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

Get the session SSL stream.

Definition at line 54 of file ssl_session.h.

Friends And Related Function Documentation

◆ SSLServer

friend class SSLServer
friend

Definition at line 29 of file ssl_session.h.


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