|
Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
|
Manages the server's event loop, handling I/O operations and dispatching tasks. More...
#include <EventLoop.hpp>

Public Member Functions | |
| EventLoop (Listener &listener, const routing::Router &router, const config::ServerConfig &config, concurrency::ThreadPool &thread_pool, network::TlsContext *tls_context=nullptr, network::UdpSocket *quic_socket=nullptr, QuicConnectionManager *quic_manager=nullptr) | |
| Constructs an EventLoop. | |
| void | run () |
| Starts the event loop. | |
| void | stop () |
| Stops the event loop. | |
| void | stop_accepting () |
| Stops accepting new connections but continues processing existing ones. | |
| void | request_shutdown (std::chrono::steady_clock::time_point deadline) |
Graceful shutdown; safe to call from any thread. Stops accepting, closes idle connections, lets in-flight requests finish (their responses carry Connection: close; HTTP/2 gets GOAWAY, WebSocket close 1001), and force-closes whatever is left at deadline. run() returns once no connection remains. | |
| void | set_tick_hook (std::function< void()> hook) |
| Registers a function the loop calls on every iteration, on the loop thread. The loop wakes at least every 200 ms, so the hook also runs when no I/O happens. | |
| concurrency::ThreadPool & | get_thread_pool () |
| Gets the thread pool. | |
| void | share_connection_limit (std::atomic< size_t > *open) |
| size_t | connection_count () const |
| Connections this loop currently holds. | |
Private Member Functions | |
| void | do_accept () |
| void | do_read_quic () |
| void | on_accepted (network::socket_t client_fd, const sockaddr_in &addr) |
| void | accept_pending () |
| void | wait_and_accept () |
| bool | reserve_slot () |
| void | pause_accepting (std::chrono::steady_clock::time_point until) |
| void | resume_accepting_if_ready () |
| bool | at_connection_limit () const |
| void | drain_step () |
Private Attributes | |
| Listener & | listener_ |
| TimerManager | timer_manager_ |
| std::unique_ptr< network::Proactor > | proactor_ |
| concurrency::ThreadPool & | thread_pool_ |
| ConnectionManager | connection_manager_ |
| network::UdpSocket * | quic_socket_ |
| QuicConnectionManager * | quic_manager_ |
| std::atomic< bool > | is_running_ {true} |
| std::function< void()> | tick_hook_ |
| std::atomic< bool > | is_accepting_ {true} |
| std::atomic< bool > | shutdown_requested_ {false} |
| std::atomic< std::chrono::steady_clock::rep > | shutdown_deadline_ {0} |
| bool | draining_ = false |
| std::chrono::seconds | websocket_ping_interval_ {0} |
| std::chrono::steady_clock::time_point | last_websocket_ping_ {} |
| size_t | max_connections_ = 0 |
| std::atomic< size_t > * | shared_open_ = nullptr |
| bool | nonblocking_accepts_ = true |
| bool | accept_paused_ = false |
| std::chrono::steady_clock::time_point | accept_resume_at_ {} |
| std::chrono::steady_clock::time_point | last_limit_warning_ {} |
Manages the server's event loop, handling I/O operations and dispatching tasks.
| orbit::server::EventLoop::EventLoop | ( | Listener & | listener, |
| const routing::Router & | router, | ||
| const config::ServerConfig & | config, | ||
| concurrency::ThreadPool & | thread_pool, | ||
| network::TlsContext * | tls_context = nullptr, |
||
| network::UdpSocket * | quic_socket = nullptr, |
||
| QuicConnectionManager * | quic_manager = nullptr |
||
| ) |
Constructs an EventLoop.
| listener | The server listener. |
| router | The router instance. |
| config | The server configuration. |
| tls_context | The TLS context (optional). |
| quic_socket | The QUIC UDP socket (optional). |
| quic_manager | The QUIC connection manager (optional). |
| thread_pool | Runs request handlers; shared by every loop of an App and must outlive this loop's connections. |
|
private |
|
private |
|
inline |
Connections this loop currently holds.
|
private |
|
private |
|
private |
|
inline |
Gets the thread pool.
|
private |
|
private |
| void orbit::server::EventLoop::request_shutdown | ( | std::chrono::steady_clock::time_point | deadline | ) |
Graceful shutdown; safe to call from any thread. Stops accepting, closes idle connections, lets in-flight requests finish (their responses carry Connection: close; HTTP/2 gets GOAWAY, WebSocket close 1001), and force-closes whatever is left at deadline. run() returns once no connection remains.
|
private |
|
private |
| void orbit::server::EventLoop::run | ( | ) |
Starts the event loop.
|
inline |
Registers a function the loop calls on every iteration, on the loop thread. The loop wakes at least every 200 ms, so the hook also runs when no I/O happens.
| void orbit::server::EventLoop::share_connection_limit | ( | std::atomic< size_t > * | open | ) |
| void orbit::server::EventLoop::stop | ( | ) |
Stops the event loop.
| void orbit::server::EventLoop::stop_accepting | ( | ) |
Stops accepting new connections but continues processing existing ones.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |