Skip to content

A lightweight, multi-threaded HTTP server implemented in C. Made with event-driven I/O with epoll, thread pooling, concurrent file access, and non-blocking resumable operations

Notifications You must be signed in to change notification settings

jtsus/httpserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Web Server

With this web server we aim to clearly separate the part of the program that handles the interactions with sockets into the IO package and the action handler which turns requests into responses into the request package. The goal of this is to allow for different functionality than what was requested for this assignment with minimal propagation of effects.

Server Implementation

This implementation of the HTTP v1.1 takes modularity and utilization as core design targets. When a request comes in it will be handled as such:

  1. epoll notifies any waiting worker that there is additional data to be accepted.
  2. The thread goes through all unparsed data and either parses the data into new requests or appends the data to uncomplete requests.
  3. Completed requests are passed into the main work queue for workers to process.
  4. Waiting workers are waked in order to attempt to process any available work in the queue if none are found they resume sleep.
  5. Work that is found gets processed through request handles and get turned into completable responses. Responses are immediately sent to the client on completion.

Code Layout

  • httpserver.c:
    • Main file behind the program, only file capable of accessing all packages in order to properly setup the environment.
    • This file chooses which request_handle should be used for each type of request.
    • This file creates workers, a global work queue, and client specific work queues which are passed to workers.
  • api:
    • completable.c/h: Object to describe data that may or may not be complete
    • request_handle.c/h: Object made to handle requests and return a response
    • queue.c/h: A concurrent sorted queue implementation (currently done using a CAS-based SkipList)
    • request.c/h: Data used to represent an HTTP request (completable)
    • response.c/h: Data used to represent an HTTP response (completable)
  • io:
    • bind.c/h: File provided by CSE130 staff that handles the binding of port to create a socket which clients may connect to.
    • worker.c/h:
      • An object-oriented approach to threaded socket IO. The following steps are attempted in each iteration of work (reverse order).
      • Handles incoming connections and parses them to be a completable request (may not be completed depending on client).
      • Handles completed requests by using a named request_handle associated to the request type to generate a completable response which is added to a queue for the requesting client.
      • Handles completed responses that are in the front of client queues.
  • request:
    • read_file.c/h: A request parser to handle GET requests for local files.
    • write_file.c/h: A request parser to handle PUT requests to overwrite local files.
  • test:
    • queue_test.c: Test file for queue module. Simple tests and concurrent tests.

About

A lightweight, multi-threaded HTTP server implemented in C. Made with event-driven I/O with epoll, thread pooling, concurrent file access, and non-blocking resumable operations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published