From 3a6d99dd467b9bd33146891db1eabc08c1fe04cf Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 13 Apr 2024 02:54:08 +0200 Subject: Better track current iobatch --- opentracker.c | 4 ++-- ot_http.c | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/opentracker.c b/opentracker.c index 73a3ff3..e025bfa 100644 --- a/opentracker.c +++ b/opentracker.c @@ -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 ); diff --git a/ot_http.c b/ot_http.c index edcfadb..c82bcdf 100644 --- 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; ibatch + 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; } -- cgit v1.2.3