A systems-programming project that implements a multithreaded HTTP/1.1 file server in C using POSIX sockets and synchronization primitives.
The server accepts concurrent GET and PUT requests, dispatches connections through a bounded producer-consumer queue, and coordinates access to individual files with reader-writer locks. The repository also includes the lower-level components developed alongside the server: a configurable reader-writer lock, a thread-safe queue, a memory allocator, and a cache-policy simulator.
- Built directly on POSIX sockets and file descriptors
- Uses a configurable worker-thread pool rather than creating a thread per request
- Applies per-resource reader-writer locks to allow concurrent reads while serializing writes
- Implements a blocking bounded queue with mutexes and condition variables
- Parses and validates HTTP request lines and headers
- Supports
GETandPUToperations with standard HTTP status responses - Produces an ordered audit log containing the method, URI, status code, and request ID
- Includes FIFO, LRU, and Clock cache-replacement simulations
+--------------------+
client connections --->| listener/dispatcher|
+---------+----------+
|
v
+-------------------+
| bounded request |
| queue |
+---------+---------+
|
+----------+----------+
| | |
v v v
worker worker worker
| | |
+----------+----------+
|
v
per-file reader-writer locks
|
v
local filesystem
The main thread owns the listening socket and places accepted client sockets into a shared queue. A fixed-size worker pool consumes those connections and processes one request per connection. Before accessing a file, each worker acquires the resource's reader or writer lock: multiple GET operations can proceed together, while PUT operations receive exclusive access.
The server implements a focused subset of HTTP/1.1:
| Method | Behavior | Success response |
|---|---|---|
GET /file |
Returns the contents of a local file | 200 OK |
PUT /file |
Creates or replaces a local file with the request body | 201 Created or 200 OK |
It also returns appropriate error responses for malformed requests, unsupported methods or protocol versions, missing files, directories, and internal I/O failures.
Each completed supported request is written to standard error in this format:
<method>,<uri>,<status-code>,<request-id>
For example:
PUT,/message.txt,201,42
GET,/message.txt,200,43
- A Linux environment compatible with the bundled helper library
clangmake- POSIX threads
Build the concurrent server:
make -C asgn4Start it with the default four-worker pool:
./asgn4/httpserver 8080Or select the number of worker threads:
./asgn4/httpserver -t 8 8080The server reads and writes files relative to the directory from which it is launched.
Note
The networking helper library in asgn4/ is included as a precompiled archive from the project's original Linux environment. Building on another operating system or architecture requires a compatible build of that library. Newer compilers may also report additional diagnostics because the Makefile promotes all warnings to errors.
With the server running on port 8080, create a file:
curl -i -X PUT \
-H 'Content-Length: 13' \
-H 'Request-Id: 42' \
--data-binary 'Hello, world!' \
http://localhost:8080/message.txtRetrieve it:
curl -i \
-H 'Request-Id: 43' \
http://localhost:8080/message.txtClean the build artifacts with:
make -C asgn4 clean.
├── asgn1/ custom memory allocator
├── asgn2/ single-threaded HTTP server
├── asgn3/ bounded queue and reader-writer lock
├── asgn4/ concurrent HTTP server
└── asgn5/ cache-policy simulator
The numbered directories preserve the project's progression from low-level memory management and networking fundamentals to synchronization, concurrent request processing, and cache behavior.
This project explores the systems concepts behind a network service rather than relying on a web framework:
- socket lifecycle and connection handling
- HTTP message parsing and response construction
- partial reads and writes over file descriptors
- producer-consumer coordination
- mutexes and condition variables
- reader/writer fairness policies
- resource-level synchronization
- filesystem I/O and status-code mapping
- cache replacement and miss classification
This is an educational HTTP/1.1 implementation intended to demonstrate operating-systems and concurrency fundamentals. It supports a deliberately small protocol surface and is not intended to replace a hardened, production-grade web server.