CppServer
1.0.4.0
C++ Server Library
|
SSL server. More...
#include <ssl_server.h>
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 |
SSLServer & | operator= (const SSLServer &)=delete |
SSLServer & | operator= (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< SSLSession > | FindSession (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< SSLSession > | CreateSession (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 |
SSL server.
SSL server is used to connect, disconnect and manage SSL sessions.
Thread-safe.
Definition at line 31 of file ssl_server.h.
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.
service | - Asio service |
context | - SSL context |
port | - Port number |
protocol | - Internet protocol type (default is IPv4) |
Definition at line 14 of file ssl_server.cpp.
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.
service | - Asio service |
context | - SSL context |
address | - Server address |
port | - Port number |
Definition at line 52 of file ssl_server.cpp.
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.
service | - Asio service |
context | - SSL context |
endpoint | - Server SSL endpoint |
Definition at line 83 of file ssl_server.cpp.
|
delete |
|
delete |
|
virtualdefault |
|
inlinenoexcept |
Get the server acceptor.
Definition at line 80 of file ssl_server.h.
|
inlinenoexcept |
Get the server address.
Definition at line 83 of file ssl_server.h.
|
inlinenoexcept |
Get the number of bytes pending sent by the server.
Definition at line 90 of file ssl_server.h.
|
inlinenoexcept |
Get the number of bytes received by the server.
Definition at line 94 of file ssl_server.h.
|
inlinenoexcept |
Get the number of bytes sent by the server.
Definition at line 92 of file ssl_server.h.
|
inlinenoexcept |
Get the number of sessions connected to the server.
Definition at line 88 of file ssl_server.h.
|
inlinenoexcept |
Get the server SSL context.
Definition at line 76 of file ssl_server.h.
|
inlineprotectedvirtual |
Create SSL session factory method.
server | - SSL server |
Definition at line 188 of file ssl_server.h.
|
virtual |
Disconnect all connected sessions.
Definition at line 274 of file ssl_server.cpp.
|
inlinenoexcept |
Get the server endpoint.
Definition at line 78 of file ssl_server.h.
std::shared_ptr< SSLSession > CppServer::Asio::SSLServer::FindSession | ( | const CppCommon::UUID & | id | ) |
Find a session with a given Id.
id | - Session Id |
Definition at line 300 of file ssl_server.cpp.
|
inlinenoexcept |
Get the server Id.
Definition at line 67 of file ssl_server.h.
|
inlinenoexcept |
Get the Asio IO service.
Definition at line 72 of file ssl_server.h.
|
inlinenoexcept |
Is the server started?
Definition at line 106 of file ssl_server.h.
|
virtual |
Multicast data to all connected sessions.
buffer | - Buffer to multicast |
size | - Buffer size |
Reimplemented in CppServer::WS::WSSServer.
Definition at line 253 of file ssl_server.cpp.
|
inlinevirtual |
Multicast text to all connected sessions.
text | - Text to multicast |
Definition at line 136 of file ssl_server.h.
|
inlineprotectedvirtual |
Handle session connected notification.
session | - Connected session |
Definition at line 200 of file ssl_server.h.
|
inlineprotectedvirtual |
Handle session disconnected notification.
session | - Disconnected session |
Definition at line 210 of file ssl_server.h.
|
inlineprotectedvirtual |
Handle error notification.
error | - Error code |
category | - Error category |
message | - Error message |
Definition at line 218 of file ssl_server.h.
|
inlineprotectedvirtual |
Handle session handshaked notification.
session | - Handshaked session |
Definition at line 205 of file ssl_server.h.
|
inlineprotectedvirtual |
Handle server started notification.
Definition at line 192 of file ssl_server.h.
|
inlineprotectedvirtual |
Handle server stopped notification.
Definition at line 194 of file ssl_server.h.
|
inlinenoexcept |
Get the option: keep alive.
Definition at line 97 of file ssl_server.h.
|
inlinenoexcept |
Get the option: no delay.
Definition at line 99 of file ssl_server.h.
|
inlinenoexcept |
Get the option: reuse address.
Definition at line 101 of file ssl_server.h.
|
inlinenoexcept |
Get the option: reuse port.
Definition at line 103 of file ssl_server.h.
|
inlinenoexcept |
Get the server port number.
Definition at line 85 of file ssl_server.h.
|
virtual |
Restart the server.
Definition at line 201 of file ssl_server.cpp.
|
inlinenoexcept |
Get the Asio service.
Definition at line 70 of file ssl_server.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 157 of file ssl_server.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 166 of file ssl_server.h.
|
inlinenoexcept |
Setup option: reuse address.
This option will enable/disable SO_REUSEADDR if the OS support this feature.
enable | - Enable/disable option |
Definition at line 173 of file ssl_server.h.
|
inlinenoexcept |
Setup option: reuse port.
This option will enable/disable SO_REUSEPORT if the OS support this feature.
enable | - Enable/disable option |
Definition at line 180 of file ssl_server.h.
|
virtual |
Start the server.
Definition at line 112 of file ssl_server.cpp.
|
virtual |
Stop the server.
Definition at line 162 of file ssl_server.cpp.
|
inlinenoexcept |
Get the Asio service strand for serialized handler execution.
Definition at line 74 of file ssl_server.h.
|
friend |
Definition at line 33 of file ssl_server.h.
|
protected |
Definition at line 223 of file ssl_server.h.
|
protected |
Definition at line 222 of file ssl_server.h.