summaryrefslogtreecommitdiff
path: root/opentracker.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-27 03:05:43 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-27 03:05:43 +0100
commitfa0f7ee6dba3ba14a6fc1172e04a161f514d94b0 (patch)
treef418d15698caf353e25557f8139b3d87a1513b32 /opentracker.c
parent0d6e0044a104176d6d6f2111fda1d7c1f160a583 (diff)
Revive http keep alive to save tcp connection setup costs
Diffstat (limited to 'opentracker.c')
-rw-r--r--opentracker.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/opentracker.c b/opentracker.c
index 21eeb42..11da486 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -177,12 +177,13 @@ static void handle_read(const int64_t sock, struct ot_workstruct *ws) {
177} 177}
178 178
179static void handle_write(const int64_t sock) { 179static void handle_write(const int64_t sock) {
180 struct http_data *cookie = fdstate_cookie(sock); 180 struct http_data *cookie = fdstate_cookie(sock);
181 int chunked = 0; 181 int chunked = 0;
182 int keep_alive = 0;
182 183
183 if (cookie) { 184 if (cookie) {
184 if (cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER) 185 chunked = (cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER) != 0;
185 chunked = 1; 186 keep_alive = (cookie->flag & STRUCT_HTTP_FLAG_KEEPALIVE) != 0;
186 187
187 if (cookie->batch) { 188 if (cookie->batch) {
188 if (batch_send(sock, cookie->batch) == BATCH_FAILED) { 189 if (batch_send(sock, cookie->batch) == BATCH_FAILED) {
@@ -197,7 +198,13 @@ static void handle_write(const int64_t sock) {
197 /* In a chunked transfer, wait for the next piece once everything queued has gone out */ 198 /* In a chunked transfer, wait for the next piece once everything queued has gone out */
198 if (chunked) 199 if (chunked)
199 http_interest_drop(sock, cookie, EVENT_OUT); 200 http_interest_drop(sock, cookie, EVENT_OUT);
200 else 201 else if (keep_alive) {
202 /* The reply is out and the client asked to keep the connection, so stop
203 waiting to write and go back to waiting for the next request */
204 http_interest_drop(sock, cookie, EVENT_OUT);
205 http_interest_add(sock, cookie, EVENT_IN);
206 fdstate_set_expiry(sock, g_now_seconds + OT_CLIENT_TIMEOUT);
207 } else
201 handle_dead(sock); 208 handle_dead(sock);
202} 209}
203 210