refactor: moved resetting of ctx to separate function

This commit is contained in:
Jef Roosens 2023-05-28 18:24:22 +02:00
parent 590f0e5186
commit 62348c14f5
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
5 changed files with 35 additions and 17 deletions

View file

@ -1,21 +1,6 @@
#include "http_loop.h"
#include "http.h"
http_loop_gctx *http_loop_gctx_init() {
http_loop_gctx *gctx = calloc(sizeof(http_loop_gctx), 1);
return gctx;
}
http_loop_ctx *http_loop_ctx_init(http_loop_gctx *g) {
http_loop_ctx *ctx = calloc(sizeof(http_loop_ctx), 1);
ctx->g = g;
return ctx;
}
void http_loop_ctx_free(http_loop_ctx *ctx) { free(ctx); }
bool http_loop_handle_request(event_loop_conn *conn) {
// Prevents the request handler function from looping indefinitely without
// ever consuming new data

View file

@ -0,0 +1,23 @@
#include "http.h"
#include "http_loop.h"
http_loop_gctx *http_loop_gctx_init() {
http_loop_gctx *gctx = calloc(sizeof(http_loop_gctx), 1);
return gctx;
}
http_loop_ctx *http_loop_ctx_init(http_loop_gctx *g) {
http_loop_ctx *ctx = calloc(sizeof(http_loop_ctx), 1);
ctx->g = g;
return ctx;
}
void http_loop_ctx_free(http_loop_ctx *ctx) { free(ctx); }
void http_loop_ctx_reset(http_loop_ctx *ctx) {
ctx->route = NULL;
ctx->current_step = 0;
ctx->flush = false;
}

View file

@ -84,8 +84,7 @@ void http_loop_process_request(event_loop_conn *conn) {
// If we've reached the end of the list of step functions, we report the
// request as finished by clearing its route
if (ctx->route->steps[ctx->current_step] == NULL) {
ctx->route = NULL;
ctx->current_step = 0;
http_loop_ctx_reset(ctx);
}
}