From 9cb278eb2a56390360122dd721a69b7b276c52d0 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Sat, 31 Dec 2022 11:20:29 +0100 Subject: [PATCH] Remove tcp_closer --- Makefile | 4 +--- src/worker/func.h | 6 +++--- src/worker/request_handler.c | 4 +--- src/worker/tcp_acceptor.c | 12 ++++++++++++ src/worker/tcp_closer.c | 25 ------------------------- src/workers.c | 14 ++++---------- src/workers.h | 2 -- 7 files changed, 21 insertions(+), 46 deletions(-) delete mode 100644 src/worker/tcp_closer.c diff --git a/Makefile b/Makefile index 3510f22..5e64465 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ bin/worker/%.o: src/worker/%.c $(CC) -c -o $@ $(CFLAGS) $< bin/sesimos: bin/server.o bin/logger.o bin/cache_handler.o bin/async.o bin/workers.o \ - bin/worker/request_handler.o bin/worker/tcp_acceptor.o bin/worker/tcp_closer.o \ + bin/worker/request_handler.o bin/worker/tcp_acceptor.o \ bin/worker/fastcgi_handler.o bin/worker/local_handler.o bin/worker/proxy_handler.o \ bin/lib/compress.o bin/lib/config.o bin/lib/fastcgi.o bin/lib/geoip.o \ bin/lib/http.o bin/lib/http_static.o bin/lib/proxy.o bin/lib/sock.o bin/lib/uri.o \ @@ -69,8 +69,6 @@ bin/worker/request_handler.o: src/worker/func.h bin/worker/tcp_acceptor.o: src/worker/func.h -bin/worker/tcp_closer.o: src/worker/func.h - bin/worker/fastcgi_handler.o: src/worker/func.h bin/worker/local_handler.o: src/worker/func.h diff --git a/src/worker/func.h b/src/worker/func.h index 7523422..25006b2 100644 --- a/src/worker/func.h +++ b/src/worker/func.h @@ -44,8 +44,6 @@ typedef struct { void tcp_acceptor_func(client_ctx_t *ctx); -void tcp_closer_func(client_ctx_t *ctx); - void request_handler_func(client_ctx_t *ctx); void local_handler_func(client_ctx_t *ctx); @@ -58,6 +56,8 @@ void ws_frame_handler_func(ws_ctx_t *ctx); int respond(client_ctx_t *ctx); -int request_complete(client_ctx_t *ctx); +void request_complete(client_ctx_t *ctx); + +void tcp_close(client_ctx_t *ctx); #endif //SESIMOS_FUNC_H diff --git a/src/worker/request_handler.c b/src/worker/request_handler.c index 9c5887a..33145d5 100644 --- a/src/worker/request_handler.c +++ b/src/worker/request_handler.c @@ -350,7 +350,7 @@ int respond(client_ctx_t *ctx) { return 0; } -int request_complete(client_ctx_t *ctx) { +void request_complete(client_ctx_t *ctx) { // FIXME //if (close_proxy && proxy.socket != 0) { // info(BLUE_STR "Closing proxy connection"); @@ -364,6 +364,4 @@ int request_complete(client_ctx_t *ctx) { uri_free(&ctx->uri); http_free_req(&ctx->req); http_free_res(&ctx->res); - - return 0; } diff --git a/src/worker/tcp_acceptor.c b/src/worker/tcp_acceptor.c index 071c911..ef7e2d7 100644 --- a/src/worker/tcp_acceptor.c +++ b/src/worker/tcp_acceptor.c @@ -116,3 +116,15 @@ static int tcp_acceptor(client_ctx_t *ctx) { return 0; } + +void tcp_close(client_ctx_t *ctx) { + logger_set_prefix("[%*s]%s", INET6_ADDRSTRLEN, ctx->socket.s_addr, ctx->log_prefix); + + sock_close(&ctx->socket); + + ctx->cnx_e = clock_micros(); + char buf[32]; + info("Connection closed (%s)", format_duration(ctx->cnx_e - ctx->cnx_s, buf)); + + memset(ctx, 0, sizeof(*ctx)); +} diff --git a/src/worker/tcp_closer.c b/src/worker/tcp_closer.c deleted file mode 100644 index 69e0d77..0000000 --- a/src/worker/tcp_closer.c +++ /dev/null @@ -1,25 +0,0 @@ -/** - * sesimos - secure, simple, modern web server - * @brief TCP closer - * @file src/worker/tcp_closer.c - * @author Lorenz Stechauner - * @date 2022-12-28 - */ - -#include "func.h" -#include "../logger.h" -#include "../lib/utils.h" - -#include - -void tcp_closer_func(client_ctx_t *ctx) { - logger_set_prefix("[%*s]%s", INET6_ADDRSTRLEN, ctx->socket.s_addr, ctx->log_prefix); - - sock_close(&ctx->socket); - - ctx->cnx_e = clock_micros(); - char buf[32]; - info("Connection closed (%s)", format_duration(ctx->cnx_e - ctx->cnx_s, buf)); - - memset(ctx, 0, sizeof(*ctx)); -} diff --git a/src/workers.c b/src/workers.c index ea506ab..9cda320 100644 --- a/src/workers.c +++ b/src/workers.c @@ -12,12 +12,11 @@ #include "worker/func.h" #include "async.h" -static mpmc_t tcp_acceptor_ctx, tcp_closer_ctx, request_handler_ctx, +static mpmc_t tcp_acceptor_ctx, request_handler_ctx, local_handler_ctx, fastcgi_handler_cxt, proxy_handler_ctx; int workers_init(void) { - mpmc_init(&tcp_acceptor_ctx, 8, 64, (void (*)(void *)) tcp_acceptor_func, "tcp_a"); - mpmc_init(&tcp_closer_ctx, 8, 64, (void (*)(void *)) tcp_closer_func, "tcp_c"); + mpmc_init(&tcp_acceptor_ctx, 8, 64, (void (*)(void *)) tcp_acceptor_func, "tcp"); mpmc_init(&request_handler_ctx, 16, 64, (void (*)(void *)) request_handler_func, "req"); mpmc_init(&local_handler_ctx, 16, 64, (void (*)(void *)) local_handler_func, "local"); mpmc_init(&fastcgi_handler_cxt, 16, 64, (void (*)(void *)) fastcgi_handler_func, "fcgi"); @@ -31,7 +30,6 @@ void workers_stop(void) { mpmc_stop(&fastcgi_handler_cxt); mpmc_stop(&proxy_handler_ctx); mpmc_stop(&request_handler_ctx); - mpmc_stop(&tcp_closer_ctx); } void workers_destroy(void) { @@ -40,17 +38,12 @@ void workers_destroy(void) { mpmc_destroy(&fastcgi_handler_cxt); mpmc_destroy(&proxy_handler_ctx); mpmc_destroy(&request_handler_ctx); - mpmc_destroy(&tcp_closer_ctx); } int tcp_accept(client_ctx_t *ctx) { return mpmc_queue(&tcp_acceptor_ctx, ctx); } -int tcp_close(client_ctx_t *ctx) { - return mpmc_queue(&tcp_closer_ctx, ctx); -} - static int handle_request_cb(client_ctx_t *ctx) { return mpmc_queue(&request_handler_ctx, ctx); } @@ -59,7 +52,8 @@ int handle_request(client_ctx_t *ctx) { if (ctx->c_keep_alive && ctx->s_keep_alive) { return async(ctx->socket.socket, POLLIN, 0, (void (*)(void *)) handle_request_cb, ctx, (void (*)(void *)) tcp_close, ctx); } else { - return tcp_close(ctx); + tcp_close(ctx); + return 0; } } diff --git a/src/workers.h b/src/workers.h index 3ca4cb5..dda7138 100644 --- a/src/workers.h +++ b/src/workers.h @@ -19,8 +19,6 @@ void workers_destroy(void); int tcp_accept(client_ctx_t *ctx); -int tcp_close(client_ctx_t *ctx); - int handle_request(client_ctx_t *ctx); int local_handle(client_ctx_t *ctx);