diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-30 23:11:41 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-30 23:11:41 +0100 |
| commit | 15f9f81b5a8398fefca023e90d8d1c168ecef620 (patch) | |
| tree | 5661bcf9e01ea89784de285ae27312a1e752167d /ot_http.c | |
| parent | 36e396fd30bf098fa2459f11f4dd4430f7a8396e (diff) | |
Introduce a fast path assuming that a tcp connection's payload already has arrived at accept time
Diffstat (limited to 'ot_http.c')
| -rw-r--r-- | ot_http.c | 29 |
1 files changed, 25 insertions, 4 deletions
| @@ -39,9 +39,25 @@ ssize_t g_stats_path_len; | |||
| 39 | 39 | ||
| 40 | enum { SUCCESS_HTTP_HEADER_LENGTH = 80, SUCCESS_HTTP_SIZE_OFF = 17 }; | 40 | enum { SUCCESS_HTTP_HEADER_LENGTH = 80, SUCCESS_HTTP_SIZE_OFF = 17 }; |
| 41 | 41 | ||
| 42 | /* Give up a connection: the one place that knows everything hanging off it. | 42 | int http_adopt(const int64_t sock, struct http_data *cookie) { |
| 43 | The slot is released before anything is freed, so that a late event or the | 43 | struct http_data *heap = malloc(sizeof(*heap)); |
| 44 | expiry sweep finds a closed descriptor rather than a freed cookie. */ | 44 | |
| 45 | if (!heap) | ||
| 46 | return -1; | ||
| 47 | |||
| 48 | *heap = *cookie; | ||
| 49 | heap->flag &= ~STRUCT_HTTP_FLAG_ONSTACK; | ||
| 50 | fdstate_set_cookie((int)sock, heap); | ||
| 51 | |||
| 52 | if (event_add((int)sock, heap->interest, fdstate_generation((int)sock)) == -1) { | ||
| 53 | fdstate_set_cookie((int)sock, cookie); | ||
| 54 | free(heap); | ||
| 55 | return -1; | ||
| 56 | } | ||
| 57 | return 0; | ||
| 58 | } | ||
| 59 | |||
| 60 | /* Give up a connection: the one place that knows everything hanging off it. */ | ||
| 45 | void http_close(const int64_t sock) { | 61 | void http_close(const int64_t sock) { |
| 46 | struct http_data *cookie = fdstate_cookie(sock); | 62 | struct http_data *cookie = fdstate_cookie(sock); |
| 47 | 63 | ||
| @@ -54,7 +70,8 @@ void http_close(const int64_t sock) { | |||
| 54 | buf_reset(&cookie->request); | 70 | buf_reset(&cookie->request); |
| 55 | if (cookie->flag & (STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER)) | 71 | if (cookie->flag & (STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER)) |
| 56 | mutex_workqueue_canceltask(sock); | 72 | mutex_workqueue_canceltask(sock); |
| 57 | free(cookie); | 73 | if (!(cookie->flag & STRUCT_HTTP_FLAG_ONSTACK)) |
| 74 | free(cookie); | ||
| 58 | } | 75 | } |
| 59 | 76 | ||
| 60 | event_close((int)sock); | 77 | event_close((int)sock); |
| @@ -140,6 +157,10 @@ void http_interest_set(const int64_t sock, struct http_data *cookie, int what) { | |||
| 140 | if (cookie->interest == what) | 157 | if (cookie->interest == what) |
| 141 | return; | 158 | return; |
| 142 | cookie->interest = what; | 159 | cookie->interest = what; |
| 160 | /* Still on a stack, so not in the event loop yet: whoever adopts this | ||
| 161 | connection registers whatever it asked for last */ | ||
| 162 | if (cookie->flag & STRUCT_HTTP_FLAG_ONSTACK) | ||
| 163 | return; | ||
| 143 | event_modify((int)sock, what, fdstate_generation((int)sock)); | 164 | event_modify((int)sock, what, fdstate_generation((int)sock)); |
| 144 | } | 165 | } |
| 145 | 166 | ||
