- Inspiration Source
- Initialization Functions
- Create
- Destroy
- Task Queue
- Since we want the threads to check routes after creation:
- I need to find a way to do that without compromising it's extendability.
- If I directly check the route from the threadpool library, it will be tightly coupled to the server code.
- Server receives a request.
- Server sends that request to the thread pool working Queue.
- Main Thread Pool function loops infinitely; Checking if there are threads that are available and not working.
- If a thread finishes it's work, it picks up the next task in the Queue.
- Right after a worker thread picks work, it should call the RoutingManager
I want to emulate a form of MVC where we setup URL Routes (Like "/home")
and assign a function to that HTTP request.
Example usage of the proposed Routing system:
registerRoute("/home", homeHandler)
Where "homeHandler" would be a function pointer.
This is a function that will return a function pointer to the ThreadPoolWorkers. Once a Request is being processed, the ThreadPoolWorker sends the URL of the request to the RouteManager. The RouteManager shall then check if there's a match. If the HTTP Request matches a registered route, return the function pointer of that Route Struct.
If there's no match found, return a function pointer to a 'notFoundHandler'.
Once the Server Receives a HTTP Request it will be sent to a RouteMapper that checks the URL Path and sees if it matches a registered route. If there's no match, return 404 and maybe return a default NotFound page.
There's many ways to implement the HTTP and I'm not sure which one I'll implement.
The easiest thing would be to make .http files.
Create http files, name matching the http route.
Read the contents into char buffers and memcpy into HttpResponseBody.
To be able to support dynamic web sites I need to come up with ways to generate HTML. Could iteratively snprintf strings into a buffer.
- Initialise Socket
- Bind to Port and Accept Connections
- Add Incoming Requests to the Thread Pool's Task Queue.
I will look into creating a simplified and reusable HTTP Response system. This might be a function that takes a Status Code and the ResponseBody associated with the Route. It will then handle the outward communication with the connected clients.
-
- Since a different thread will respond to the HttpRequest
- We will need to pass the request to the functions that will respond to it.
-
- The ThreadPool itself
-
- Workers circulating in the thread pool
-
- A
typedefthat creates a function signature. - Psuedo version:
typedef HttpResponse (*RequestHandler)(const HttpRequest)- Function signature for a function pointer that:
- Param: A constant HttpRequest
- Returns: HttpResponse
- A
-
- A struct containing all relevant information for the response.
-
- Contains the data that the connected client sent to our server.
-
- Request URL/Path String.
- RouteHandler function pointer accociated with the Route.
- Maybe a HTML file that is returned.