]> git.ipfire.org Git - thirdparty/opentracker.git/commitdiff
Better track current iobatch
authorDirk Engling <erdgeist@erdgeist.org>
Sat, 13 Apr 2024 00:54:08 +0000 (02:54 +0200)
committerDirk Engling <erdgeist@erdgeist.org>
Sat, 13 Apr 2024 00:54:08 +0000 (02:54 +0200)
opentracker.c
ot_http.c

index 73a3ff39244198d5aadd86cb83ce8da723c28861..e025bfa9840a7dc228ea72ce5ebbb7d9b4291d1d 100644 (file)
@@ -238,8 +238,8 @@ static void handle_write( const int64 sock ) {
 
   /* In a chunked transfer after all batches accumulated have been sent, wait for the next one */
   if( chunked ) {
-//fprintf( stderr, "handle_write is STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER => dont want write on sock %lld\n", sock);
-    //io_dontwantwrite( sock );
+fprintf( stderr, "handle_write is STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER => dont want write on sock %lld\n", sock);
+    io_dontwantwrite( sock );
   } else {
 fprintf( stderr, "handle_write is STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER => handle dead on sock %lld\n", sock);
     handle_dead( sock );
index edcfadb2797102c60d39559710bef6459e576a41..c82bcdf2f9660edbba3415df7299a1f62392dcaf 100644 (file)
--- a/ot_http.c
+++ b/ot_http.c
@@ -123,6 +123,7 @@ ssize_t http_issue_error( const int64 sock, struct ot_workstruct *ws, int code )
 
 ssize_t http_sendiovecdata( const int64 sock, struct ot_workstruct *ws, int iovec_entries, struct iovec *iovector, int is_partial ) {
   struct http_data *cookie = io_getcookie( sock );
+  io_batch *current;
   char *header;
   const char *encoding = "";
   int i;
@@ -169,15 +170,19 @@ fprintf(stderr, "http_sendiovecdata sending %d iovec entries found cookie->batch
 
     if (!cookie->batch ) {
       cookie->batch = malloc( sizeof(io_batch) );
+      if (!cookie->batch) {
+        free(header);
+        iovec_free( &iovec_entries, &iovector );
+        HTTPERROR_500;
+      }
       memset( cookie->batch, 0, sizeof(io_batch) );
       cookie->batches = 1;
     }
-    iob_addbuf_free( cookie->batch, header, header_size );
+    current = cookie->batch + cookie->batches - 1;
+    iob_addbuf_free( current, header, header_size );
 
     /* Split huge iovectors into separate io_batches */
     for( i=0; i<iovec_entries; ++i ) {
-      io_batch *current = cookie->batch + cookie->batches - 1;
-
       /* If the current batch's limit is reached, try to reallocate a new batch to work on */
       if( current->bytesleft > OT_BATCH_LIMIT ) {
 fprintf(stderr, "http_sendiovecdata found batch above limit: %zd\n", current->bytesleft);
@@ -193,12 +198,13 @@ fprintf(stderr, "http_sendiovecdata calling iob_addbuf_free with %zd\n", iovecto
     }
     free( iovector );
     if ( cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER )
-      iob_addbuf(cookie->batch + cookie->batches - 1, "\r\n", 2);
+      iob_addbuf(current, "\r\n", 2);
   }
 
   if ((cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER) && cookie->batch && !is_partial) {
 fprintf(stderr, "http_sendiovecdata adds a terminating 0 size buffer to batch\n");
-    iob_addbuf(cookie->batch + cookie->batches - 1, "0\r\n\r\n", 5);
+    current = cookie->batch + cookie->batches - 1;
+    iob_addbuf(current, "0\r\n\r\n", 5);
     cookie->flag &= ~STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER;
   }