feat: add context information to requests
This commit is contained in:
parent
6d4b94c55e
commit
dfd27b579d
8 changed files with 241 additions and 183 deletions
|
|
@ -6,36 +6,35 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "http_req.h"
|
||||
#include "trie.h"
|
||||
|
||||
// Size of the read and write buffers for each connection, in bytes
|
||||
#define EVENT_LOOP_BUFFER_SIZE 1024
|
||||
|
||||
typedef struct event_loop_gctx {
|
||||
Trie *trie;
|
||||
} event_loop_gctx;
|
||||
|
||||
event_loop_gctx *event_loop_gctx_init();
|
||||
|
||||
typedef struct event_loop_ctx {
|
||||
http_request req;
|
||||
event_loop_gctx *g;
|
||||
} event_loop_ctx;
|
||||
|
||||
event_loop_ctx *event_loop_ctx_init(event_loop_gctx *g);
|
||||
|
||||
void event_loop_ctx_free(event_loop_ctx *ctx);
|
||||
|
||||
/**
|
||||
* Represents an active connection managed by the event loop
|
||||
*/
|
||||
typedef struct event_loop_conn event_loop_conn;
|
||||
|
||||
typedef enum {
|
||||
event_loop_conn_state_req = 0,
|
||||
event_loop_conn_state_res = 1,
|
||||
event_loop_conn_state_end = 2,
|
||||
} event_loop_conn_state;
|
||||
|
||||
/*
|
||||
* Main struct object representing the event loop
|
||||
*/
|
||||
typedef struct event_loop event_loop;
|
||||
|
||||
/*
|
||||
* Initialize a new event loop
|
||||
*/
|
||||
event_loop *event_loop_init();
|
||||
|
||||
/*
|
||||
* Run the event loop. This function never returns.
|
||||
*/
|
||||
void event_loop_run(event_loop *el, int port);
|
||||
|
||||
typedef struct event_loop_conn {
|
||||
int fd;
|
||||
event_loop_conn_state state;
|
||||
|
|
@ -51,24 +50,34 @@ typedef struct event_loop_conn {
|
|||
// If true, the server will close the connection after the final write buffer
|
||||
// has been written
|
||||
bool close_after_write;
|
||||
/* void (*process_func)(struct event_loop_conn *); */
|
||||
http_request req;
|
||||
event_loop_ctx *ctx;
|
||||
} event_loop_conn;
|
||||
|
||||
/*
|
||||
* Initialize a new event_loop_conn struct
|
||||
*/
|
||||
event_loop_conn *event_loop_conn_init();
|
||||
event_loop_conn *event_loop_conn_init(event_loop_gctx *g);
|
||||
|
||||
void event_loop_conn_free(event_loop_conn *conn);
|
||||
|
||||
/*
|
||||
* Process data on a connection
|
||||
*/
|
||||
void event_loop_conn_io(event_loop_conn *conn);
|
||||
|
||||
/*
|
||||
* Main struct object representing the event loop
|
||||
*/
|
||||
typedef struct event_loop {
|
||||
event_loop_conn **connections;
|
||||
size_t connection_count;
|
||||
event_loop_gctx *gctx;
|
||||
} event_loop;
|
||||
|
||||
/*
|
||||
* Initialize a new event_loop struct
|
||||
*/
|
||||
event_loop *event_loop_init();
|
||||
event_loop *event_loop_init(event_loop_gctx *g);
|
||||
|
||||
/*
|
||||
* Place a new connection into the event loop's internal array.
|
||||
|
|
@ -82,6 +91,9 @@ int event_loop_put(event_loop *loop, event_loop_conn *conn);
|
|||
*/
|
||||
int event_loop_accept(event_loop *loop, int fd);
|
||||
|
||||
void event_loop_conn_io(event_loop_conn *conn);
|
||||
/*
|
||||
* Run the event loop. This function never returns.
|
||||
*/
|
||||
void event_loop_run(event_loop *el, int port);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue