From 15f9f81b5a8398fefca023e90d8d1c168ecef620 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Fri, 30 Oct 2026 23:11:41 +0100 Subject: Introduce a fast path assuming that a tcp connection's payload already has arrived at accept time --- ot_http.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'ot_http.c') diff --git a/ot_http.c b/ot_http.c index 66f0102..bb6ff24 100644 --- a/ot_http.c +++ b/ot_http.c @@ -39,9 +39,25 @@ ssize_t g_stats_path_len; enum { SUCCESS_HTTP_HEADER_LENGTH = 80, SUCCESS_HTTP_SIZE_OFF = 17 }; -/* Give up a connection: the one place that knows everything hanging off it. - The slot is released before anything is freed, so that a late event or the - expiry sweep finds a closed descriptor rather than a freed cookie. */ +int http_adopt(const int64_t sock, struct http_data *cookie) { + struct http_data *heap = malloc(sizeof(*heap)); + + if (!heap) + return -1; + + *heap = *cookie; + heap->flag &= ~STRUCT_HTTP_FLAG_ONSTACK; + fdstate_set_cookie((int)sock, heap); + + if (event_add((int)sock, heap->interest, fdstate_generation((int)sock)) == -1) { + fdstate_set_cookie((int)sock, cookie); + free(heap); + return -1; + } + return 0; +} + +/* Give up a connection: the one place that knows everything hanging off it. */ void http_close(const int64_t sock) { struct http_data *cookie = fdstate_cookie(sock); @@ -54,7 +70,8 @@ void http_close(const int64_t sock) { buf_reset(&cookie->request); if (cookie->flag & (STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER)) mutex_workqueue_canceltask(sock); - free(cookie); + if (!(cookie->flag & STRUCT_HTTP_FLAG_ONSTACK)) + free(cookie); } event_close((int)sock); @@ -140,6 +157,10 @@ void http_interest_set(const int64_t sock, struct http_data *cookie, int what) { if (cookie->interest == what) return; cookie->interest = what; + /* Still on a stack, so not in the event loop yet: whoever adopts this + connection registers whatever it asked for last */ + if (cookie->flag & STRUCT_HTTP_FLAG_ONSTACK) + return; event_modify((int)sock, what, fdstate_generation((int)sock)); } -- cgit v1.3