9#ifndef CPPSERVER_ASIO_SSL_SERVER_H
10#define CPPSERVER_ASIO_SSL_SERVER_H
15#include "system/uuid.h"
19#include <shared_mutex>
31class SSLServer :
public std::enable_shared_from_this<SSLServer>
112 virtual bool Start();
149 std::shared_ptr<SSLSession>
FindSession(
const CppCommon::UUID&
id);
188 virtual std::shared_ptr<SSLSession>
CreateSession(
const std::shared_ptr<SSLServer>& server) {
return std::make_shared<SSLSession>(server); }
223 std::map<CppCommon::UUID, std::shared_ptr<SSLSession>>
_sessions;
229 std::shared_ptr<Service> _service;
231 std::shared_ptr<asio::io_service> _io_service;
233 asio::io_service::strand _strand;
234 bool _strand_required;
236 std::string _address;
239 std::shared_ptr<SSLContext> _context;
240 std::shared_ptr<SSLSession> _session;
241 asio::ip::tcp::endpoint _endpoint;
242 asio::ip::tcp::acceptor _acceptor;
243 std::atomic<bool> _started;
250 bool _option_keep_alive;
251 bool _option_no_delay;
252 bool _option_reuse_address;
253 bool _option_reuse_port;
259 void RegisterSession();
264 void UnregisterSession(
const CppCommon::UUID&
id);
270 void SendError(std::error_code
ec);
Asio allocate handler wrapper.
bool IsStarted() const noexcept
Is the server started?
std::shared_mutex _sessions_lock
void SetupReuseAddress(bool enable) noexcept
Setup option: reuse address.
bool option_no_delay() const noexcept
Get the option: no delay.
std::shared_ptr< SSLSession > FindSession(const CppCommon::UUID &id)
Find a session with a given Id.
virtual void onStopped()
Handle server stopped notification.
virtual bool Multicast(std::string_view text)
Multicast text to all connected sessions.
uint64_t bytes_received() const noexcept
Get the number of bytes received by the server.
SSLServer(SSLServer &&)=delete
SSLServer & operator=(SSLServer &&)=delete
std::shared_ptr< asio::io_service > & io_service() noexcept
Get the Asio IO service.
SSLServer & operator=(const SSLServer &)=delete
virtual bool Multicast(const void *buffer, size_t size)
Multicast data to all connected sessions.
virtual bool Stop()
Stop the server.
int port() const noexcept
Get the server port number.
std::shared_ptr< Service > & service() noexcept
Get the Asio service.
std::map< CppCommon::UUID, std::shared_ptr< SSLSession > > _sessions
virtual void onHandshaked(std::shared_ptr< SSLSession > &session)
Handle session handshaked notification.
virtual bool DisconnectAll()
Disconnect all connected sessions.
const std::string & address() const noexcept
Get the server address.
virtual void onStarted()
Handle server started notification.
virtual void onConnected(std::shared_ptr< SSLSession > &session)
Handle session connected notification.
bool option_reuse_port() const noexcept
Get the option: reuse port.
asio::io_service::strand & strand() noexcept
Get the Asio service strand for serialized handler execution.
uint64_t bytes_pending() const noexcept
Get the number of bytes pending sent by the server.
bool option_keep_alive() const noexcept
Get the option: keep alive.
uint64_t connected_sessions() const noexcept
Get the number of sessions connected to the server.
std::shared_ptr< SSLContext > & context() noexcept
Get the server SSL context.
void SetupNoDelay(bool enable) noexcept
Setup option: no delay.
const CppCommon::UUID & id() const noexcept
Get the server Id.
virtual ~SSLServer()=default
asio::ip::tcp::acceptor & acceptor() noexcept
Get the server acceptor.
virtual void onError(int error, const std::string &category, const std::string &message)
Handle error notification.
uint64_t bytes_sent() const noexcept
Get the number of bytes sent by the server.
void SetupReusePort(bool enable) noexcept
Setup option: reuse port.
virtual void onDisconnected(std::shared_ptr< SSLSession > &session)
Handle session disconnected notification.
void SetupKeepAlive(bool enable) noexcept
Setup option: keep alive.
SSLServer(const SSLServer &)=delete
virtual bool Restart()
Restart the server.
virtual bool Start()
Start the server.
asio::ip::tcp::endpoint & endpoint() noexcept
Get the server endpoint.
bool option_reuse_address() const noexcept
Get the option: reuse address.
virtual std::shared_ptr< SSLSession > CreateSession(const std::shared_ptr< SSLServer > &server)
Create SSL session factory method.
InternetProtocol
Internet protocol.
@ IPv4
Internet Protocol version 4.
C++ Server project definitions.