From 195eb9eb4832f80ee8ab2372192196018362b252 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 9 Mar 2024 20:28:50 +0100 Subject: [PATCH] chore: remove unneeded code; add throughput example --- Makefile | 2 +- example/throughput.c | 53 ++++++++++++++++++++++++++++++++++++++++++ include/lnm/http/req.h | 1 - 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 example/throughput.c diff --git a/Makefile b/Makefile index e52bb1f..be76159 100644 --- a/Makefile +++ b/Makefile @@ -81,7 +81,7 @@ $(BUILD_DIR)/$(TEST_DIR)/%.c.o: $(TEST_DIR)/%.c build-example: $(BINS_EXAMPLE) $(BINS_EXAMPLE): %: %.c.o $(LIB) - $(CC) \ + $(CC) $(LDFLAGS) \ $^ -o $@ # Example binaries link the resulting library diff --git a/example/throughput.c b/example/throughput.c new file mode 100644 index 0000000..b2704a8 --- /dev/null +++ b/example/throughput.c @@ -0,0 +1,53 @@ +#include "lnm/http/res.h" +#include "lnm/log.h" +#include "lnm/http/loop.h" +#include "lnm/loop.h" + +lnm_err ctx_init(void **c_ctx, void *gctx) { + *c_ctx = NULL; + + return lnm_err_ok; +} + +void ctx_reset(void *c_ctx) {} +void ctx_free(void *c_ctx) {} + +lnm_err data_streamer(uint64_t *written, char *buf, + lnm_http_conn *conn, uint64_t offset, + uint64_t len) { + // Don't do anything, just let the application return random data stored in + // the read buffer. The goal is to benchmark the networking pipeline + *written = len; + + return lnm_err_ok; +} + +lnm_http_step_err step_fn(lnm_http_conn *conn) { + lnm_http_loop_ctx *ctx = conn->ctx; + uint64_t len = 1 << 30; + lnm_http_res_body_set_fn(&ctx->res, data_streamer, len); + + return lnm_http_step_err_done; +} + +int main() { + lnm_http_loop *hl; + + lnm_http_loop_init(&hl, NULL, ctx_init, + ctx_reset, + ctx_free); + + lnm_http_router *router; + lnm_http_router_init(&router); + + lnm_http_route *route; + lnm_http_router_add(&route, router, lnm_http_method_get, "/"); + lnm_http_route_step_append(route, step_fn, false); + + lnm_http_loop_router_set(hl, router); + + lnm_log_init_global(); + lnm_log_register_stdout(lnm_log_level_warning); + + printf("res = %i\n", lnm_http_loop_run(hl, 8080, 1, 0)); +} diff --git a/include/lnm/http/req.h b/include/lnm/http/req.h index 1c32972..146fb81 100644 --- a/include/lnm/http/req.h +++ b/include/lnm/http/req.h @@ -40,7 +40,6 @@ typedef struct lnm_http_req { struct { size_t o; size_t len; - regmatch_t groups[LNM_HTTP_MAX_REGEX_GROUPS]; } path; struct { size_t o;