feat: started designing http framework

This commit is contained in:
Jef Roosens 2023-05-27 15:38:06 +02:00
parent 90d83bc5d4
commit 8250a5b8b0
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
9 changed files with 96 additions and 50 deletions

View file

@ -172,7 +172,7 @@ void event_loop_run(event_loop *el, int port) {
// poll for active fds
// the timeout argument doesn't matter here
int rv = poll(poll_args, (nfds_t)poll_args_count, 0);
int rv = poll(poll_args, (nfds_t)poll_args_count, -1);
if (rv < 0) {
critical(1, "Poll failed, errno: %i", errno);

View file

@ -109,7 +109,6 @@ void event_loop_conn_io(event_loop *el, event_loop_conn *conn) {
case event_loop_conn_state_res:
event_loop_conn_io_res(conn);
break;
case event_loop_conn_state_end:
break;
case event_loop_conn_state_end:;
}
}

View file

@ -31,7 +31,7 @@ bool http_loop_handle_request(event_loop_conn *conn) {
if (res == http_parse_error_ok) {
// Perform the request
http_route(conn);
/* http_route(conn); */
}
// Both in the case of an invalid HTTP request or one that's larger than the
// read buffer, we cannot determine when the next, possibly valid, HTTP

View file

@ -3,11 +3,11 @@
#include "event_loop.h"
#include "http.h"
typedef void (*routing_func)(event_loop_conn *);
void http_loop_process_request(event_loop_conn *conn) {}
void http_route(event_loop_conn *conn) {
// TODO routing
/* void http_route(event_loop_conn *conn) { */
/* // TODO routing */
// Fallthrough is to return a 404
http_write_standard_response(conn, http_not_found);
}
/* // Fallthrough is to return a 404 */
/* http_write_standard_response(conn, http_not_found); */
/* } */

View file

@ -1,8 +1,21 @@
#include <stdio.h>
#include "http.h"
#include "http_loop.h"
#include "log.h"
void http_write_404(event_loop_conn *conn) {
memcpy(conn->wbuf, http_404, http_404_len);
conn->state = event_loop_conn_state_res;
conn->wbuf_size = http_404_len;
conn->wbuf_sent = 0;
}
void (*steps[])(event_loop_conn *) = {http_write_404, NULL};
http_route routes[] = {
{.type = http_route_literal, .path = "/", .step_count = 1, .steps = steps}};
int main() {
setvbuf(stdout, NULL, _IONBF, 0);