summaryrefslogtreecommitdiff
path: root/opentracker.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-25 22:30:04 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-25 22:30:04 +0100
commit0e3a2189f65354962fc71af41f5aa52261a782e8 (patch)
treeeae9ec0a8930ae7cc2de02b9ed1d797bfbc2e6e8 /opentracker.c
parent3f7d4f4e8bc8cd9928fd0b1b280eb4c3f0ca9fa5 (diff)
Replace libowfat's iobatch with our own smaller (and probably only temporary) ot_batch
Diffstat (limited to 'opentracker.c')
-rw-r--r--opentracker.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/opentracker.c b/opentracker.c
index 96a265a..50fff29 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -23,7 +23,6 @@
23 23
24/* Libowfat */ 24/* Libowfat */
25#include "io.h" 25#include "io.h"
26#include "iob.h"
27 26
28/* Opentracker */ 27/* Opentracker */
29#include "ot_accesslist.h" 28#include "ot_accesslist.h"
@@ -120,9 +119,8 @@ static ssize_t header_complete(char *request, ssize_t byte_count) {
120static void handle_dead(const int64_t sock) { 119static void handle_dead(const int64_t sock) {
121 struct http_data *cookie = io_getcookie(sock); 120 struct http_data *cookie = io_getcookie(sock);
122 if (cookie) { 121 if (cookie) {
123 size_t i; 122 if (cookie->batch)
124 for (i = 0; i < cookie->batches; ++i) 123 batch_reset(cookie->batch);
125 iob_reset(cookie->batch + i);
126 free(cookie->batch); 124 free(cookie->batch);
127 buf_reset(&cookie->request); 125 buf_reset(&cookie->request);
128 if (cookie->flag & (STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER)) 126 if (cookie->flag & (STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER))
@@ -178,33 +176,23 @@ static void handle_read(const int64_t sock, struct ot_workstruct *ws) {
178 176
179static void handle_write(const int64_t sock) { 177static void handle_write(const int64_t sock) {
180 struct http_data *cookie = io_getcookie(sock); 178 struct http_data *cookie = io_getcookie(sock);
181 size_t i;
182 int chunked = 0; 179 int chunked = 0;
183 180
184 /* Look for the first io_batch still containing bytes to write */
185 if (cookie) { 181 if (cookie) {
186 if (cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER) 182 if (cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER)
187 chunked = 1; 183 chunked = 1;
188 184
189 for (i = 0; i < cookie->batches; ++i) { 185 if (cookie->batch) {
190 if (cookie->batch[i].bytesleft) { 186 if (batch_send(sock, cookie->batch) == BATCH_FAILED) {
191 int64_t res = iob_send(sock, cookie->batch + i); 187 handle_dead(sock);
192 188 return;
193 if (res == -3) {
194 handle_dead(sock);
195 return;
196 }
197
198 if (!cookie->batch[i].bytesleft)
199 continue;
200
201 if (res == -1 || res > 0 || i < cookie->batches - 1)
202 return;
203 } 189 }
190 if (batch_pending(cookie->batch))
191 return;
204 } 192 }
205 } 193 }
206 194
207 /* In a chunked transfer after all batches accumulated have been sent, wait for the next one */ 195 /* In a chunked transfer, wait for the next piece once everything queued has gone out */
208 if (chunked) 196 if (chunked)
209 io_dontwantwrite(sock); 197 io_dontwantwrite(sock);
210 else 198 else