|
Network System 0.1.1
High-performance modular networking library for scalable client-server applications
|
HTTP/2 server with TLS support. More...
#include <http2_server.h>


Public Types | |
| using | request_handler_t |
| Request handler function type. | |
| using | error_handler_t |
| Error handler function type. | |
Public Member Functions | |
| http2_server (std::string_view server_id) | |
| Construct HTTP/2 server. | |
| ~http2_server () | |
| Destructor - stops server gracefully. | |
| http2_server (const http2_server &)=delete | |
| http2_server & | operator= (const http2_server &)=delete |
| http2_server (http2_server &&)=delete | |
| http2_server & | operator= (http2_server &&)=delete |
| auto | start (unsigned short port) -> VoidResult |
| Start HTTP/2 server without TLS (h2c - HTTP/2 cleartext) | |
| auto | start_tls (unsigned short port, const tls_config &config) -> VoidResult |
| Start HTTP/2 server with TLS. | |
| auto | stop () -> VoidResult |
| Stop the server. | |
| auto | is_running () const -> bool |
| Check if server is running. | |
| auto | wait () -> void |
| Wait for server to stop. | |
| auto | set_request_handler (request_handler_t handler) -> void |
| Set request handler. | |
| auto | set_error_handler (error_handler_t handler) -> void |
| Set error handler. | |
| auto | set_settings (const http2_settings &settings) -> void |
| Set server settings. | |
| auto | get_settings () const -> http2_settings |
| Get current settings. | |
| auto | active_connections () const -> size_t |
| Get number of active connections. | |
| auto | active_streams () const -> size_t |
| Get total number of active streams across all connections. | |
| auto | server_id () const -> std::string_view |
| Get server identifier. | |
Private Member Functions | |
| auto | do_accept () -> void |
| auto | do_accept_tls () -> void |
| auto | handle_accept (std::error_code ec, asio::ip::tcp::socket socket) -> void |
| auto | handle_accept_tls (std::error_code ec, asio::ip::tcp::socket socket) -> void |
| auto | add_connection (std::shared_ptr< http2_server_connection > conn) -> void |
| auto | remove_connection (uint64_t connection_id) -> void |
| auto | cleanup_dead_connections () -> void |
| auto | start_cleanup_timer () -> void |
| auto | run_io () -> void |
| auto | stop_io () -> void |
Private Attributes | |
| std::string | server_id_ |
| Server identifier. | |
| std::unique_ptr< asio::io_context > | io_context_ |
| std::unique_ptr< asio::ssl::context > | ssl_context_ |
| std::unique_ptr< asio::ip::tcp::acceptor > | acceptor_ |
| std::unique_ptr< asio::executor_work_guard< asio::io_context::executor_type > > | work_guard_ |
| std::future< void > | io_future_ |
| std::atomic< bool > | is_running_ {false} |
| std::atomic< bool > | use_tls_ {false} |
| std::promise< void > | stop_promise_ |
| std::future< void > | stop_future_ |
| request_handler_t | request_handler_ |
| error_handler_t | error_handler_ |
| std::mutex | connections_mutex_ |
| std::map< uint64_t, std::shared_ptr< http2_server_connection > > | connections_ |
| std::atomic< uint64_t > | next_connection_id_ {1} |
| http2_settings | settings_ |
| std::shared_ptr< hpack_encoder > | encoder_ |
| std::shared_ptr< hpack_decoder > | decoder_ |
| std::unique_ptr< asio::steady_timer > | cleanup_timer_ |
Static Private Attributes | |
| static constexpr std::string_view | CONNECTION_PREFACE |
| static constexpr size_t | FRAME_HEADER_SIZE = 9 |
HTTP/2 server with TLS support.
Definition at line 92 of file http2_server.h.
Error handler function type.
Definition at line 101 of file http2_server.h.
Request handler function type.
Definition at line 96 of file http2_server.h.
|
explicit |
Construct HTTP/2 server.
| server_id | Unique server identifier for logging |
Definition at line 16 of file http2_server.cpp.
| kcenon::network::protocols::http2::http2_server::~http2_server | ( | ) |
Destructor - stops server gracefully.
Definition at line 24 of file http2_server.cpp.
References is_running_, and stop().

|
delete |
|
delete |
|
nodiscard |
Get number of active connections.
Definition at line 219 of file http2_server.cpp.
|
nodiscard |
Get total number of active streams across all connections.
Definition at line 225 of file http2_server.cpp.
|
private |
Definition at line 334 of file http2_server.cpp.
|
private |
Definition at line 346 of file http2_server.cpp.
|
private |
Definition at line 240 of file http2_server.cpp.
|
private |
Definition at line 252 of file http2_server.cpp.
|
nodiscard |
Get current settings.
Definition at line 214 of file http2_server.cpp.
|
private |
Definition at line 264 of file http2_server.cpp.
|
private |
Definition at line 291 of file http2_server.cpp.
|
nodiscard |
Check if server is running.
Definition at line 187 of file http2_server.cpp.
|
delete |
|
delete |
|
private |
Definition at line 340 of file http2_server.cpp.
|
private |
Definition at line 374 of file http2_server.cpp.
|
nodiscard |
| auto kcenon::network::protocols::http2::http2_server::set_error_handler | ( | error_handler_t | handler | ) | -> void |
Set error handler.
| handler | Function to handle errors |
Definition at line 202 of file http2_server.cpp.
| auto kcenon::network::protocols::http2::http2_server::set_request_handler | ( | request_handler_t | handler | ) | -> void |
Set request handler.
| handler | Function to handle incoming requests |
The handler is called for each complete HTTP/2 request. Handler should not block for long periods.
Definition at line 197 of file http2_server.cpp.
| auto kcenon::network::protocols::http2::http2_server::set_settings | ( | const http2_settings & | settings | ) | -> void |
Set server settings.
| settings | HTTP/2 settings to use |
Definition at line 207 of file http2_server.cpp.
References kcenon::network::protocols::http2::settings.
| auto kcenon::network::protocols::http2::http2_server::start | ( | unsigned short | port | ) | -> VoidResult |
Start HTTP/2 server without TLS (h2c - HTTP/2 cleartext)
| port | Port to listen on |
Definition at line 31 of file http2_server.cpp.
References kcenon::network::error_codes::common_errors::already_exists, kcenon::network::error_codes::network_system::bind_failed, kcenon::network::error_void(), and kcenon::network::ok().

|
private |
Definition at line 358 of file http2_server.cpp.
| auto kcenon::network::protocols::http2::http2_server::start_tls | ( | unsigned short | port, |
| const tls_config & | config ) -> VoidResult |
Start HTTP/2 server with TLS.
| port | Port to listen on |
| config | TLS configuration |
Starts the server with TLS and ALPN "h2" negotiation.
Definition at line 68 of file http2_server.cpp.
References kcenon::network::error_codes::common_errors::already_exists, config, kcenon::network::error_void(), and kcenon::network::ok().

| auto kcenon::network::protocols::http2::http2_server::stop | ( | ) | -> VoidResult |
Stop the server.
Sends GOAWAY to all connections and stops accepting new connections.
Definition at line 147 of file http2_server.cpp.
References kcenon::network::ok().
Referenced by ~http2_server().


|
private |
Definition at line 381 of file http2_server.cpp.
| auto kcenon::network::protocols::http2::http2_server::wait | ( | ) | -> void |
Wait for server to stop.
Blocks until stop() is called.
Definition at line 192 of file http2_server.cpp.
|
private |
Definition at line 231 of file http2_server.h.
|
private |
Definition at line 258 of file http2_server.h.
|
staticconstexprprivate |
Definition at line 261 of file http2_server.h.
|
private |
Definition at line 247 of file http2_server.h.
|
private |
Definition at line 246 of file http2_server.h.
|
private |
Definition at line 255 of file http2_server.h.
|
private |
Definition at line 254 of file http2_server.h.
|
private |
Definition at line 243 of file http2_server.h.
|
staticconstexprprivate |
Definition at line 263 of file http2_server.h.
|
private |
Definition at line 229 of file http2_server.h.
|
private |
Definition at line 233 of file http2_server.h.
|
private |
|
private |
Definition at line 248 of file http2_server.h.
|
private |
Definition at line 242 of file http2_server.h.
|
private |
Server identifier.
Definition at line 226 of file http2_server.h.
|
private |
Definition at line 251 of file http2_server.h.
|
private |
Definition at line 230 of file http2_server.h.
|
private |
Definition at line 239 of file http2_server.h.
|
private |
Definition at line 238 of file http2_server.h.
|
private |
Definition at line 237 of file http2_server.h.
|
private |
Definition at line 232 of file http2_server.h.