feat(lnm): write server init code
This commit is contained in:
parent
3c74200bbd
commit
e59ee38ae2
6 changed files with 195 additions and 4 deletions
|
|
@ -23,6 +23,7 @@ typedef enum {
|
|||
lnm_err_failed_network,
|
||||
lnm_err_failed_poll,
|
||||
lnm_err_not_setup,
|
||||
lnm_err_bad_regex
|
||||
} lnm_err;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
70
lnm/include/lnm/http/loop.h
Normal file
70
lnm/include/lnm/http/loop.h
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#ifndef LNM_HTTP_LOOP
|
||||
#define LNM_HTTP_LOOP
|
||||
|
||||
#include "lnm/common.h"
|
||||
|
||||
typedef struct lnm_loop lnm_http_loop;
|
||||
|
||||
typedef struct lnm_http_conn lnm_http_conn;
|
||||
|
||||
typedef struct lnm_http_step lnm_http_step;
|
||||
|
||||
typedef struct lnm_http_route lnm_http_route;
|
||||
|
||||
typedef lnm_err (*lnm_http_step_fn)(lnm_http_conn *conn);
|
||||
|
||||
/**
|
||||
* Initialize a new `lnm_http_loop`.
|
||||
*
|
||||
* @param out where to store pointer to new `lnm_http_loop`
|
||||
*/
|
||||
lnm_err lnm_http_loop_init(lnm_http_loop **out);
|
||||
|
||||
/**
|
||||
* Initialize a first step
|
||||
*
|
||||
* @param out where to store pointer to new `lnm_http_step`
|
||||
* @param fn step function associated with the step
|
||||
*/
|
||||
lnm_err lnm_http_step_init(lnm_http_step **out, lnm_http_step_fn fn);
|
||||
|
||||
/**
|
||||
* Append the given step fn to the step.
|
||||
*
|
||||
* @param out where to store pointer to new `lnm_http_step`
|
||||
* @param step step to append new step to
|
||||
* @param fn step funcitonn
|
||||
*/
|
||||
lnm_err lnm_http_step_append(lnm_http_step **out, lnm_http_step *step,
|
||||
lnm_http_step_fn fn);
|
||||
|
||||
/**
|
||||
* Initialize a new route of type literal.
|
||||
*
|
||||
* @param out where to store pointer to new `lnm_http_route`
|
||||
* @param path literal path to match
|
||||
* @param step step to process request with
|
||||
*/
|
||||
lnm_err lnm_http_route_init_literal(lnm_http_route **out, const char *path,
|
||||
lnm_http_step *step);
|
||||
|
||||
/**
|
||||
* Initialize a new route of type regex.
|
||||
*
|
||||
* @param out where to store pointer to new `lnm_http_route`
|
||||
* @param pattern regex pattern
|
||||
* @param regex_group_count how many regex groups are contained in the pattern
|
||||
* @param step step to process request with
|
||||
*/
|
||||
lnm_err lnm_http_route_init_regex(lnm_http_route **out, const char *pattern,
|
||||
int regex_group_count, lnm_http_step *step);
|
||||
|
||||
/**
|
||||
* Add a new route to the HTTP route.
|
||||
*
|
||||
* @param hl HTTP loop to modify
|
||||
* @param route route to add
|
||||
*/
|
||||
void lnm_http_loop_route_add(lnm_http_loop *hl, lnm_http_route *route);
|
||||
|
||||
#endif
|
||||
|
|
@ -30,7 +30,7 @@ typedef struct {
|
|||
} w;
|
||||
} lnm_loop_conn;
|
||||
|
||||
typedef struct {
|
||||
typedef struct lnm_loop {
|
||||
int listen_fd;
|
||||
struct {
|
||||
lnm_loop_conn **arr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue