How lhd-creator/fastserver works
Project Type and Purpose
• This is a C++ concurrent‐server framework, modeled after muduo, targeting Linux.
• It provides a Reactor‐based core library for building high‐performance network services (TCP, HTTP, timers, thread pool), plus several examples (HTTP server, echo server, timer wheel).
File Structure Analysis
• Top‐level directories:
• Example/… – standalone demo apps (Any, Timer, Timewheel)
• source/… – core library headers & source, subfolders for Http module, tests, examples, echo and WebBench.
• Key modules in source/:
• EventLoop.hpp, Poller.hpp, Channel.hpp – Reactor core
• TcpServer.hpp, Connection.hpp, TcpSocket.hpp – TCP abstraction
• TimerWheel.hpp, LoopThreadPool.hpp – scheduling & concurrency
• Http/… – HTTP client/server examples & wwwroot
• examples under source/example – repeat of top-level Example for reference
Core Components
a. EventLoop
b. Poller (epoll abstraction)
c. Channel (file‐descriptor wrapper & callback registry)
d. TcpServer (listens for new connections)
e. Connection (manages a single client session)
f. TimerWheel (manages scheduled callbacks)
g. LoopThreadPool (multiple EventLoop threads)
h. HTTP Module (parsing, request/response handling)
i. Example Applications (Echo, HTTP server, Timer tests)
Component Interactions & Data Flows
• OS/epoll → Poller
• Poller → EventLoop
• EventLoop dispatches via Channel to:
• Connection callbacks (read/write/close)
• TimerWheel callbacks (timeout events)
• New client connections: Poller triggers TcpServer → creates Connection → registers with EventLoop
• TimerWheel schedules timers; on expiry pushes tasks into EventLoop
• LoopThreadPool: main EventLoop accepts connections and distributes to worker EventLoops
• HTTP module sits on top of Connection to parse requests and generate responses
Architectural Patterns & Design Principles
• Reactor pattern (EventLoop + Poller + Channel)
• Single‐threaded event loop with optional thread pool for concurrency
• Modular layering: core library (network + timer), protocol (HTTP), examples
• Pluggable scheduling: TimerWheel for O(1) timeouts