25#ifndef QB_IO_ASYNC_TCP_ACCEPTOR_H
26#define QB_IO_ASYNC_TCP_ACCEPTOR_H
35namespace qb::io::async::tcp {
49template <
typename _Derived,
typename _Prot>
51 :
public input<acceptor<_Derived, _Prot>>
57 typename _Prot::socket_type>;
73 on(event::disconnected &&e) {
74 if constexpr (has_method_on<_Derived, void, event::disconnected>::value)
75 static_cast<_Derived &
>(*this).on(std::forward<event::disconnected>(e));
77 throw std::runtime_error(
"Acceptor has been disconnected");
93 : base_t(new Protocol(*this)) {}
110 static_cast<_Derived &
>(*this).on(
111 std::forward<typename Protocol::message>(new_socket));
123 std::filesystem::path cert_file = {},
124 std::filesystem::path key_file = {},
125 std::vector<std::string> alpn_protocols = {}) {
127 using tpt = std::decay_t<
decltype(this->transport())>;
128 if constexpr (tpt::is_secure()) {
130 if (!this->transport().ssl_handle()) {
131 LOG_CRIT(
"Failed to initialize SSL/TLS server context.");
134 this->transport().set_supported_alpn_protocols(std::move(alpn_protocols));
137 return !this->transport().listen(std::move(uri));
typename transport::accept::socket_type accepted_socket_type
Definition acceptor.h:84
~acceptor()=default
Destructor.
bool listen(qb::io::uri uri, std::filesystem::path cert_file={}, std::filesystem::path key_file={}, std::vector< std::string > alpn_protocols={})
Listen for incoming connections on a given URI.
Definition acceptor.h:122
void on(typename Protocol::message &&new_socket)
Handler for new connections.
Definition acceptor.h:109
acceptor() noexcept
Constructor.
Definition acceptor.h:92
void on(event::disconnected &&e)
Handler for disconnection events.
Definition acceptor.h:73
Protocol for handling the acceptance of new network connections.
Definition accept.h:46
_Socket message
Type alias for the socket type.
Definition accept.h:52
Class for parsing, manipulating, and representing URIs.
Definition uri.h:181
SSL_CTX * create_server_context(const SSL_METHOD *method, std::filesystem::path cert_path, std::filesystem::path key_path)
Create an SSL context (SSL_CTX) configured for server-side SSL/TLS operations.
Core asynchronous I/O class templates for event-driven operations.
#define LOG_CRIT(X)
Critical-level log macro (no-op if QB_STDOUT_LOG is not defined)
Definition io.h:243
Protocol for accepting new connections in asynchronous I/O.
Implementation of a secure SSL/TLS listener for the QB IO library.