< Previous: Performance & Tuning | 🏠 Home
Architecture & Threading Model
cpp-http inherits its multi-threaded, asynchronous architecture from cpp-tcpnet. This ensures that network IO, request parsing, and route callback processing do not block your main application logic.
The Three Threading Pillars
-
The Poller Thread: The underlying
TcpListenerspawns a background thread that monitors client sockets using non-blocking OS selectors (pollorWSAPoll). This thread is responsible for receiving TCP byte blocks and sending outgoing responses. -
The Worker Pool: Whenever new TCP bytes are read, they are pushed as work items onto a
cppasyncworker::WorkerPoolthread pool. TheHandleIncomingDataprotocol engine runs concurrently on these worker threads, parsing the HTTP headers and executing your route handler callbacks. -
The Event Cleanup Thread: To clean up session buffers when connections drop,
HttpServersubscribes to client disconnect events viacpppubsub::PubSub. It runs a dedicated, detached background thread that checks for disconnected session events and safely deletes inactive buffers from thesessions_map.
Sibling Libraries
cpp-http acts as a protocol layer on top of a highly optimized stack:
- cpp-tcpnet: The foundational socket management, polling loops, and TLS engine.
- cpp-pubsub: The event broker that coordinates state cleanups.
- cpp-asyncworker: The worker thread pool scheduling network tasks.