This commit is contained in:
2026-09-21 16:27:47 -07:00
parent e123c6344d
commit ad48802d54
2 changed files with 2 additions and 14 deletions
-6
View File
@@ -103,11 +103,6 @@ int start_server(server *s) {
// use v6_addr->sin6_port, etc.
}
// TODO: call recv until we have the end of the headers and request
// append to a buffer, resizing along the way?
// TODO: helper method which takes the client_fd and creates a request
// we can call recv until we receive \r\n\r\n
bool processing = true;
char data[4096] = {0};
size_t data_size = sizeof(data);
@@ -137,7 +132,6 @@ int start_server(server *s) {
resp->http_code = 404; // default
resp->body = "default";
// find the relevant route handler, call it
for (int i = 0; i < s->handlers_len; i++) {
printf("checking if route handler matches. path: %s\n", s->handlers[i]->path);
if (strstr(data, s->handlers[i]->path) != NULL) {
+1 -7
View File
@@ -25,11 +25,9 @@ typedef struct {
char *body;
} response;
// TODO: handlers need a way to respond to requests, maybe return a response with http code and body response
// we will provide them an already-allocated resp struct which they may fill
typedef void (*route_handler)(request *req, response *resp);
// addr should be in dot-separated notation
// addr should be in dot-separated notation (e.g. "0.0.0.0")
// returns NULL if error during creation
server *create_server(const char *addr, uint16_t port_number);
@@ -40,8 +38,4 @@ void destroy_server(server *s);
int start_server(server *s);
int register_route(server *s, const char *route, route_handler handler);
// TODO: implementation wise, we need the server to handle incoming connections, read the incoming bytes of the connection in another thread, and then route handlers from different threads...will this lead to various problems?
/* - what if a route handler uses some shared resource (e.g. service handler) to fulfill the request? and different calls of the handler from different threads calls that service handler? */
/* - keep it single-threaded for now. process one request at a time */
#endif // SERVER_H