Compare commits
15 Commits
cb07e3a8a3
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
68b63d3038
|
|||
|
1b8aad7e91
|
|||
| e611700c69 | |||
| 698f67d174 | |||
| 3ab01575a2 | |||
| 656b3ade80 | |||
| 1e81a75a8a | |||
| ace7e4b05e | |||
| cf8ddf14bf | |||
| 5dfbdc43c0 | |||
| 5d631b594f | |||
| ba8c94d971 | |||
| 1005650ea6 | |||
| 92acec0893 | |||
| 6ec79f686f |
@@ -2,3 +2,4 @@ httpserver
|
|||||||
compile_commands.json
|
compile_commands.json
|
||||||
bin/
|
bin/
|
||||||
config.json
|
config.json
|
||||||
|
.cache/
|
||||||
|
|||||||
@@ -3,3 +3,6 @@
|
|||||||
Final extra credit assignment for UCSC CSE130 Spring 2026.
|
Final extra credit assignment for UCSC CSE130 Spring 2026.
|
||||||
|
|
||||||
Build with `make` and run with `./httpserver <port>`.
|
Build with `make` and run with `./httpserver <port>`.
|
||||||
|
|
||||||
|
While I don't think it will come up, note that `assignment.pdf` is not mine and
|
||||||
|
is *NOT* AGPL'ed. It is just here for easy access.
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"course": "CSE130-W26-BRANDT",
|
|
||||||
"assignment": "extra_credit",
|
|
||||||
"server": "http://lighthouse.soe.ucsc.edu",
|
|
||||||
"user": "arosenb1@ucsc.edu",
|
|
||||||
"pass": "05beb4aef80d919bdf992f1e3ec0c33e"
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,48 @@
|
|||||||
/*
|
/*
|
||||||
* Design Doc:
|
* ##############
|
||||||
|
* # Design Doc #
|
||||||
|
* ##############
|
||||||
* The server is broken into the following files:
|
* The server is broken into the following files:
|
||||||
* - main.c: Argument parsing and high-level control
|
* - main.c: Argument parsing and high-level control
|
||||||
* - http.c: HTTP request parsing and response formatting
|
* - http.c: HTTP request parsing and response formatting
|
||||||
* - server.c: Abstraction over sockets
|
* - server.c: Abstraction over sockets
|
||||||
* - threadpool.c: Thread pool and woker queue implementation
|
* - threadpool.c: Thread pool and woker queue implementation
|
||||||
* - util.c: Misc. utility functions
|
* - util.c: Misc. utility functions
|
||||||
|
*
|
||||||
|
* Parallelization:
|
||||||
|
* I use a thread pool (implemented in threadpool.{h,c}) for parallelization. It
|
||||||
|
* uses a job queue that allows threads to push tasks (functions and a datum) to
|
||||||
|
* the queue and then distributes these tasks out to threads. It also makes sure
|
||||||
|
* to take a cleanup function in case the queue is destroyed before a given task
|
||||||
|
* is executed. Also, all the worker threads have a signal mask installed that
|
||||||
|
* prevents them frow receiving any signals (except KILL, CONT, and STOP, of
|
||||||
|
* course), so none of the tasks need to worry about such things.
|
||||||
|
*
|
||||||
|
* Abstraction:
|
||||||
|
* All multithreading stuff is contained in threadpool.{h,c}. Other files don't
|
||||||
|
* need to worry about what thread they are running on, they just need to ensure
|
||||||
|
* their functions are multithread safe.
|
||||||
|
*
|
||||||
|
* All HTTP stuff is handled in http.{h,c}. This includes both parsing requests
|
||||||
|
* and formatting responses. None of the other files do any major parsing, they
|
||||||
|
* just call into http.c and its `HTTPRequest` and `HTTPResponse` objects for
|
||||||
|
* that.
|
||||||
|
*
|
||||||
|
* Socket stuff is handled in server.{h,c}. The `Server` object contained in
|
||||||
|
* this file is a thin wrapper around the POSIX sockets API.
|
||||||
|
*
|
||||||
|
* util.{h,c} has some wrappers around the `malloc` family of functions that
|
||||||
|
* ensure that the application crashes "cleanly" if it is out of memory. As some
|
||||||
|
* functions want to catch these kinds of errors, they aren't used everywhere.
|
||||||
|
*
|
||||||
|
* Argument parsing and the request-to-task flow is handled in main.c. This is
|
||||||
|
* also where signal handling stuff is set up to ensure clean shutdown.
|
||||||
|
*
|
||||||
|
* Testing:
|
||||||
|
* I tested the server using cURL and netcat. I used cURL to create various
|
||||||
|
* kinds of syntactically valid requests. I used netcat (along with a text
|
||||||
|
* editor) to create and send syntactically invalid requests (e.g. `nc
|
||||||
|
* 127.0.0.1:8080 <test`).
|
||||||
*/
|
*/
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user