knaxuslearn · build · ship

Projects / HTTP server / Before you start

Before you start

The server uses epoll, which exists only on Linux. If you are on a Mac, run everything inside a Linux container or virtual machine (Docker Desktop, OrbStack and Lima all work). Windows users can use WSL 2. Check your compiler and your tools:

gcc --version
curl --version | head -1
python3 --version

Every listing and command in this project was run with gcc 13.3 and Python 3.12 on x86-64 Linux. Timings will differ on your machine; the shapes of the results will not. Make a folder with a tiny site to serve:

mkdir webserver && cd webserver
mkdir www
echo '<!doctype html><title>tiny</title><h1>Hello from the tiny server</h1>' > www/index.html
echo 'body { font-family: sans-serif; }' > www/style.css

Compile every program with the same flags, and keep the warnings on:

gcc -std=gnu11 -O2 -Wall -Wextra -o server server.c

Each phase below starts a fresh copy of the server in its own folder (d1, d2, and so on) so that you can run an old version next to a new one. Every folder needs its own www directory, because the server reads files from www in the folder where it runs.