summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2024-04-13 02:54:08 +0200
committerDirk Engling <erdgeist@erdgeist.org>2024-04-13 02:54:08 +0200
commit3a6d99dd467b9bd33146891db1eabc08c1fe04cf (patch)
tree0b27e515537966b594c43089a118c9e472f25756
parent1a70d9f9ef81ac1b5e843ac71f3538f7845e03ae (diff)
Better track current iobatch
-rw-r--r--opentracker.c4
-rw-r--r--ot_http.c16
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 ) {
238 238
239 /* In a chunked transfer after all batches accumulated have been sent, wait for the next one */ 239 /* In a chunked transfer after all batches accumulated have been sent, wait for the next one */
240 if( chunked ) { 240 if( chunked ) {
241//fprintf( stderr, "handle_write is STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER => dont want write on sock %lld\n", sock); 241fprintf( stderr, "handle_write is STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER => dont want write on sock %lld\n", sock);
242 //io_dontwantwrite( sock ); 242 io_dontwantwrite( sock );
243 } else { 243 } else {
244fprintf( stderr, "handle_write is STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER => handle dead on sock %lld\n", sock); 244fprintf( stderr, "handle_write is STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER => handle dead on sock %lld\n", sock);
245 handle_dead( sock ); 245 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 )
123 123
124ssize_t http_sendiovecdata( const int64 sock, struct ot_workstruct *ws, int iovec_entries, struct iovec *iovector, int is_partial ) { 124ssize_t http_sendiovecdata( const int64 sock, struct ot_workstruct *ws, int iovec_entries, struct iovec *iovector, int is_partial ) {
125 struct http_data *cookie = io_getcookie( sock ); 125 struct http_data *cookie = io_getcookie( sock );
126 io_batch *current;
126 char *header; 127 char *header;
127 const char *encoding = ""; 128 const char *encoding = "";
128 int i; 129 int i;
@@ -169,15 +170,19 @@ fprintf(stderr, "http_sendiovecdata sending %d iovec entries found cookie->batch
169 170
170 if (!cookie->batch ) { 171 if (!cookie->batch ) {
171 cookie->batch = malloc( sizeof(io_batch) ); 172 cookie->batch = malloc( sizeof(io_batch) );
173 if (!cookie->batch) {
174 free(header);
175 iovec_free( &iovec_entries, &iovector );
176 HTTPERROR_500;
177 }
172 memset( cookie->batch, 0, sizeof(io_batch) ); 178 memset( cookie->batch, 0, sizeof(io_batch) );
173 cookie->batches = 1; 179 cookie->batches = 1;
174 } 180 }
175 iob_addbuf_free( cookie->batch, header, header_size ); 181 current = cookie->batch + cookie->batches - 1;
182 iob_addbuf_free( current, header, header_size );
176 183
177 /* Split huge iovectors into separate io_batches */ 184 /* Split huge iovectors into separate io_batches */
178 for( i=0; i<iovec_entries; ++i ) { 185 for( i=0; i<iovec_entries; ++i ) {
179 io_batch *current = cookie->batch + cookie->batches - 1;
180
181 /* If the current batch's limit is reached, try to reallocate a new batch to work on */ 186 /* If the current batch's limit is reached, try to reallocate a new batch to work on */
182 if( current->bytesleft > OT_BATCH_LIMIT ) { 187 if( current->bytesleft > OT_BATCH_LIMIT ) {
183fprintf(stderr, "http_sendiovecdata found batch above limit: %zd\n", current->bytesleft); 188fprintf(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
193 } 198 }
194 free( iovector ); 199 free( iovector );
195 if ( cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER ) 200 if ( cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER )
196 iob_addbuf(cookie->batch + cookie->batches - 1, "\r\n", 2); 201 iob_addbuf(current, "\r\n", 2);
197 } 202 }
198 203
199 if ((cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER) && cookie->batch && !is_partial) { 204 if ((cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER) && cookie->batch && !is_partial) {
200fprintf(stderr, "http_sendiovecdata adds a terminating 0 size buffer to batch\n"); 205fprintf(stderr, "http_sendiovecdata adds a terminating 0 size buffer to batch\n");
201 iob_addbuf(cookie->batch + cookie->batches - 1, "0\r\n\r\n", 5); 206 current = cookie->batch + cookie->batches - 1;
207 iob_addbuf(current, "0\r\n\r\n", 5);
202 cookie->flag &= ~STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER; 208 cookie->flag &= ~STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER;
203 } 209 }
204 210