By Houdaifa Drahm
An HTTP server has to turn an arbitrary stream of bytes into complete requests while serving more than one client. A browser can send half a request and go quiet. A client can read a response slowly enough that only part of it fits in the socket buffer. A useful server makes progress on other connections in both situations.
This guide builds the design in stages. Start with a static file on one listener. Then add incremental HTTP parsing, buffered writes, routing, uploads, and CGI. The examples use C++98-friendly data structures and Linux networking APIs.
What epoll actually tells you
On Linux, create an epoll instance, use epoll_ctl() to register or modify the descriptors you care about, and call epoll_wait() to obtain ready events. The kernel maintains an interest list and a ready list. The program still has to accept connections, read bytes, interpret HTTP, and send a response.…