From e667a79ab2140c17155de24e111f347f5f4d60d0 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Sat, 31 Dec 2022 02:14:20 +0100 Subject: [PATCH] Closing connection if no keep alive --- src/worker/request_handler.c | 2 +- src/workers.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/worker/request_handler.c b/src/worker/request_handler.c index c64f4de..592b5a7 100644 --- a/src/worker/request_handler.c +++ b/src/worker/request_handler.c @@ -16,7 +16,6 @@ #include "../server.h" #include -#include #include static int request_handler(client_ctx_t *ctx); @@ -27,6 +26,7 @@ void request_handler_func(client_ctx_t *ctx) { switch (request_handler(ctx)) { case 0: respond(ctx); + request_complete(ctx); handle_request(ctx); break; case 1: diff --git a/src/workers.c b/src/workers.c index 8a3ae1b..ea506ab 100644 --- a/src/workers.c +++ b/src/workers.c @@ -56,7 +56,11 @@ static int handle_request_cb(client_ctx_t *ctx) { } int handle_request(client_ctx_t *ctx) { - return async(ctx->socket.socket, POLLIN, 0, (void (*)(void *)) handle_request_cb, ctx, (void (*)(void *)) tcp_close, 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); + } } int local_handle(client_ctx_t *ctx) {