This project involved building a high-performance HTTP/1.1 server in C that handles concurrent client requests through a custom thread pool architecture. The server implements GET and PUT operations while solving complex synchronization challenges through custom-built reader-writer locks and thread-safe data structures, all developed from scratch without external libraries.
The core innovation lies in the file-level locking system I designed, which allows multiple threads to read different files simultaneously while ensuring exclusive access during writes. I implemented three distinct priority modes for the reader-writer locks: READERS (favoring concurrent reads), WRITERS (prioritizing exclusive writes), and N_WAY (allowing N reads before giving writers priority). This approach maximizes performance by avoiding global locks while maintaining data integrity across all file operations.
The architecture features a main thread that accepts connections and distributes them through a custom producer-consumer queue to configurable worker threads. I built the queue implementation using POSIX condition variables and mutexes, ensuring efficient task distribution without race conditions. The server includes comprehensive HTTP protocol support with regex-based request parsing, proper Content-Length handling, and appropriate status code responses (200, 201, 400, 403, 404, 500, etc.).
Additional production-ready features include thread-safe audit logging for all operations, graceful shutdown with complete resource cleanup, and robust error handling for network failures and malformed requests.