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

SSL server. More...

#include <ssl_server.h>

Inheritance diagram for CppServer::Asio::SSLServer:
CppServer::HTTP::HTTPSServer CppServer::WS::WSSServer

Public Member Functions

 SSLServer (const std::shared_ptr< Service > &service, const std::shared_ptr< SSLContext > &context, int port, InternetProtocol protocol=InternetProtocol::IPv4)
 Initialize SSL server with a given Asio service, SSL context and port number. More...
 
 SSLServer (const std::shared_ptr< Service > &service, const std::shared_ptr< SSLContext > &context, const std::string &address, int port)
 Initialize SSL server with a given Asio service, SSL context, server address and port number. More...
 
 SSLServer (const std::shared_ptr< Service > &service, const std::shared_ptr< SSLContext > &context, const asio::ip::tcp::endpoint &endpoint)
 Initialize SSL server with a given a given Asio service, SSL context and endpoint. More...
 
 SSLServer (const SSLServer &)=delete
 
 SSLServer (SSLServer &&)=delete
 
virtual ~SSLServer ()=default
 
SSLServeroperator= (const SSLServer &)=delete
 
SSLServeroperator= (SSLServer &&)=delete
 
const CppCommon::UUID & id () const noexcept
 Get the server 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 server SSL context. More...
 
asio::ip::tcp::endpoint & endpoint () noexcept
 Get the server endpoint. More...
 
asio::ip::tcp::acceptor & acceptor () noexcept
 Get the server acceptor. More...
 
const std::string & address () const noexcept
 Get the server address. More...
 
int port () const noexcept
 Get the server port number. More...
 
uint64_t connected_sessions () const noexcept
 Get the number of sessions connected to the server. More...
 
uint64_t bytes_pending () const noexcept
 Get the number of bytes pending sent by the server. More...
 
uint64_t bytes_sent () const noexcept
 Get the number of bytes sent by the server. More...
 
uint64_t bytes_received () const noexcept
 Get the number of bytes received by the server. 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...
 
bool option_reuse_address () const noexcept
 Get the option: reuse address. More...
 
bool option_reuse_port () const noexcept
 Get the option: reuse port. More...
 
bool IsStarted () const noexcept
 Is the server started? More...
 
virtual bool Start ()
 Start the server. More...
 
virtual bool Stop ()
 Stop the server. More...
 
virtual bool Restart ()
 Restart the server. More...
 
virtual bool Multicast (const void *buffer, size_t size)
 Multicast data to all connected sessions. More...
 
virtual bool Multicast (std::string_view text)
 Multicast text to all connected sessions. More...
 
virtual bool DisconnectAll ()
 Disconnect all connected sessions. More...
 
std::shared_ptr< SSLSessionFindSession (const CppCommon::UUID &id)
 Find a session with a given Id. More...
 
void SetupKeepAlive (bool enable) noexcept
 Setup option: keep alive. More...
 
void SetupNoDelay (bool enable) noexcept
 Setup option: no delay. More...
 
void SetupReuseAddress (bool enable) noexcept
 Setup option: reuse address. More...
 
void SetupReusePort (bool enable) noexcept
 Setup option: reuse port. More...
 

Protected Member Functions

virtual std::shared_ptr< SSLSessionCreateSession (const std::shared_ptr< SSLServer > &server)
 Create SSL session factory method. More...
 
virtual void onStarted ()
 Handle server started notification. More...
 
virtual void onStopped ()
 Handle server stopped notification. More...
 
virtual void onConnected (std::shared_ptr< SSLSession > &session)
 Handle session connected notification. More...
 
virtual void onHandshaked (std::shared_ptr< SSLSession > &session)
 Handle session handshaked notification. More...
 
virtual void onDisconnected (std::shared_ptr< SSLSession > &session)
 Handle session disconnected notification. More...
 
virtual void onError (int error, const std::string &category, const std::string &message)
 Handle error notification. More...
 

Protected Attributes

std::shared_mutex _sessions_lock
 
std::map< CppCommon::UUID, std::shared_ptr< SSLSession > > _sessions
 

Friends

class SSLSession
 

Detailed Description

SSL server.

SSL server is used to connect, disconnect and manage SSL sessions.

Thread-safe.

Examples
ssl_chat_server.cpp.

Definition at line 31 of file ssl_server.h.

Constructor & Destructor Documentation

◆ SSLServer() [1/5]

CppServer::Asio::SSLServer::SSLServer ( const std::shared_ptr< Service > &  service,
const std::shared_ptr< SSLContext > &  context,
int  port,
InternetProtocol  protocol = InternetProtocol::IPv4 
)

Initialize SSL server with a given Asio service, SSL context and port number.

Parameters
service- Asio service
context- SSL context
port- Port number
protocol- Internet protocol type (default is IPv4)
Examples
ssl_chat_server.cpp.

Definition at line 14 of file ssl_server.cpp.

◆ SSLServer() [2/5]

CppServer::Asio::SSLServer::SSLServer ( const std::shared_ptr< Service > &  service,
const std::shared_ptr< SSLContext > &  context,
const std::string &  address,
int  port 
)

Initialize SSL server with a given Asio service, SSL context, server address and port number.

Parameters
service- Asio service
context- SSL context
address- Server address
port- Port number

Definition at line 52 of file ssl_server.cpp.

◆ SSLServer() [3/5]

CppServer::Asio::SSLServer::SSLServer ( const std::shared_ptr< Service > &  service,
const std::shared_ptr< SSLContext > &  context,
const asio::ip::tcp::endpoint &  endpoint 
)

Initialize SSL server with a given 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_server.cpp.

◆ SSLServer() [4/5]

CppServer::Asio::SSLServer::SSLServer ( const SSLServer )
delete

◆ SSLServer() [5/5]

CppServer::Asio::SSLServer::SSLServer ( SSLServer &&  )
delete

◆ ~SSLServer()

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

Member Function Documentation

◆ acceptor()

asio::ip::tcp::acceptor& CppServer::Asio::SSLServer::acceptor ( )
inlinenoexcept

Get the server acceptor.

Definition at line 80 of file ssl_server.h.

◆ address()

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

Get the server address.

Definition at line 83 of file ssl_server.h.

◆ bytes_pending()

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

Get the number of bytes pending sent by the server.

Definition at line 90 of file ssl_server.h.

◆ bytes_received()

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

Get the number of bytes received by the server.

Definition at line 94 of file ssl_server.h.

◆ bytes_sent()

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

Get the number of bytes sent by the server.

Definition at line 92 of file ssl_server.h.

◆ connected_sessions()

uint64_t CppServer::Asio::SSLServer::connected_sessions ( ) const
inlinenoexcept

Get the number of sessions connected to the server.

Definition at line 88 of file ssl_server.h.

◆ context()

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

Get the server SSL context.

Definition at line 76 of file ssl_server.h.

◆ CreateSession()

virtual std::shared_ptr<SSLSession> CppServer::Asio::SSLServer::CreateSession ( const std::shared_ptr< SSLServer > &  server)
inlineprotectedvirtual

Create SSL session factory method.

Parameters
server- SSL server
Returns
SSL session
Examples
ssl_chat_server.cpp.

Definition at line 188 of file ssl_server.h.

◆ DisconnectAll()

bool CppServer::Asio::SSLServer::DisconnectAll ( )
virtual

Disconnect all connected sessions.

Returns
'true' if all sessions were successfully disconnected, 'false' if the server is not started

Definition at line 274 of file ssl_server.cpp.

◆ endpoint()

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

Get the server endpoint.

Definition at line 78 of file ssl_server.h.

◆ FindSession()

std::shared_ptr< SSLSession > CppServer::Asio::SSLServer::FindSession ( const CppCommon::UUID &  id)

Find a session with a given Id.

Parameters
id- Session Id
Returns
Session with a given Id or null if the session it not connected

Definition at line 300 of file ssl_server.cpp.

◆ id()

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

Get the server Id.

Definition at line 67 of file ssl_server.h.

◆ io_service()

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

Get the Asio IO service.

Definition at line 72 of file ssl_server.h.

◆ IsStarted()

bool CppServer::Asio::SSLServer::IsStarted ( ) const
inlinenoexcept

Is the server started?

Definition at line 106 of file ssl_server.h.

◆ Multicast() [1/2]

bool CppServer::Asio::SSLServer::Multicast ( const void *  buffer,
size_t  size 
)
virtual

Multicast data to all connected sessions.

Parameters
buffer- Buffer to multicast
size- Buffer size
Returns
'true' if the data was successfully multicast, 'false' if the server is not started

Reimplemented in CppServer::WS::WSSServer.

Definition at line 253 of file ssl_server.cpp.

◆ Multicast() [2/2]

virtual bool CppServer::Asio::SSLServer::Multicast ( std::string_view  text)
inlinevirtual

Multicast text to all connected sessions.

Parameters
text- Text to multicast
Returns
'true' if the text was successfully multicast, 'false' if the server is not started

Definition at line 136 of file ssl_server.h.

◆ onConnected()

virtual void CppServer::Asio::SSLServer::onConnected ( std::shared_ptr< SSLSession > &  session)
inlineprotectedvirtual

Handle session connected notification.

Parameters
session- Connected session

Definition at line 200 of file ssl_server.h.

◆ onDisconnected()

virtual void CppServer::Asio::SSLServer::onDisconnected ( std::shared_ptr< SSLSession > &  session)
inlineprotectedvirtual

Handle session disconnected notification.

Parameters
session- Disconnected session

Definition at line 210 of file ssl_server.h.

◆ onError()

virtual void CppServer::Asio::SSLServer::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 218 of file ssl_server.h.

◆ onHandshaked()

virtual void CppServer::Asio::SSLServer::onHandshaked ( std::shared_ptr< SSLSession > &  session)
inlineprotectedvirtual

Handle session handshaked notification.

Parameters
session- Handshaked session

Definition at line 205 of file ssl_server.h.

◆ onStarted()

virtual void CppServer::Asio::SSLServer::onStarted ( )
inlineprotectedvirtual

Handle server started notification.

Definition at line 192 of file ssl_server.h.

◆ onStopped()

virtual void CppServer::Asio::SSLServer::onStopped ( )
inlineprotectedvirtual

Handle server stopped notification.

Definition at line 194 of file ssl_server.h.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ option_keep_alive()

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

Get the option: keep alive.

Definition at line 97 of file ssl_server.h.

◆ option_no_delay()

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

Get the option: no delay.

Definition at line 99 of file ssl_server.h.

◆ option_reuse_address()

bool CppServer::Asio::SSLServer::option_reuse_address ( ) const
inlinenoexcept

Get the option: reuse address.

Definition at line 101 of file ssl_server.h.

◆ option_reuse_port()

bool CppServer::Asio::SSLServer::option_reuse_port ( ) const
inlinenoexcept

Get the option: reuse port.

Definition at line 103 of file ssl_server.h.

◆ port()

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

Get the server port number.

Definition at line 85 of file ssl_server.h.

◆ Restart()

bool CppServer::Asio::SSLServer::Restart ( )
virtual

Restart the server.

Returns
'true' if the server was successfully restarted, 'false' if the server failed to restart

Definition at line 201 of file ssl_server.cpp.

◆ service()

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

Get the Asio service.

Definition at line 70 of file ssl_server.h.

◆ SetupKeepAlive()

void CppServer::Asio::SSLServer::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 157 of file ssl_server.h.

◆ SetupNoDelay()

void CppServer::Asio::SSLServer::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 166 of file ssl_server.h.

◆ SetupReuseAddress()

void CppServer::Asio::SSLServer::SetupReuseAddress ( bool  enable)
inlinenoexcept

Setup option: reuse address.

This option will enable/disable SO_REUSEADDR if the OS support this feature.

Parameters
enable- Enable/disable option

Definition at line 173 of file ssl_server.h.

◆ SetupReusePort()

void CppServer::Asio::SSLServer::SetupReusePort ( bool  enable)
inlinenoexcept

Setup option: reuse port.

This option will enable/disable SO_REUSEPORT if the OS support this feature.

Parameters
enable- Enable/disable option

Definition at line 180 of file ssl_server.h.

◆ Start()

bool CppServer::Asio::SSLServer::Start ( )
virtual

Start the server.

Returns
'true' if the server was successfully started, 'false' if the server failed to start

Definition at line 112 of file ssl_server.cpp.

◆ Stop()

bool CppServer::Asio::SSLServer::Stop ( )
virtual

Stop the server.

Returns
'true' if the server was successfully stopped, 'false' if the server is already stopped

Definition at line 162 of file ssl_server.cpp.

◆ strand()

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

Get the Asio service strand for serialized handler execution.

Definition at line 74 of file ssl_server.h.

Friends And Related Function Documentation

◆ SSLSession

friend class SSLSession
friend

Definition at line 33 of file ssl_server.h.

Member Data Documentation

◆ _sessions

std::map<CppCommon::UUID, std::shared_ptr<SSLSession> > CppServer::Asio::SSLServer::_sessions
protected

Definition at line 223 of file ssl_server.h.

◆ _sessions_lock

std::shared_mutex CppServer::Asio::SSLServer::_sessions_lock
protected

Definition at line 222 of file ssl_server.h.


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