summaryrefslogtreecommitdiff
path: root/ot_http.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_http.c')
-rw-r--r--ot_http.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/ot_http.c b/ot_http.c
index e05db72..390878b 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -31,6 +31,7 @@
31#include "ot_accesslist.h" 31#include "ot_accesslist.h"
32 32
33#define OT_MAXMULTISCRAPE_COUNT 64 33#define OT_MAXMULTISCRAPE_COUNT 64
34#define OT_BATCH_LIMIT (1024*1024*16)
34extern char *g_redirecturl; 35extern char *g_redirecturl;
35 36
36char *g_stats_path; 37char *g_stats_path;
@@ -75,7 +76,13 @@ static void http_senddata( const int64 sock, struct ot_workstruct *ws ) {
75 } 76 }
76 77
77 memcpy( outbuf, ws->reply + written_size, ws->reply_size - written_size ); 78 memcpy( outbuf, ws->reply + written_size, ws->reply_size - written_size );
78 iob_addbuf_free( &cookie->batch, outbuf, ws->reply_size - written_size ); 79 if ( !cookie->batch ) {
80 cookie->batch = malloc( sizeof(io_batch) );
81 memset( cookie->batch, 0, sizeof(io_batch) );
82 cookie->batches = 1;
83 }
84
85 iob_addbuf_free( cookie->batch, outbuf, ws->reply_size - written_size );
79 86
80 /* writeable short data sockets just have a tcp timeout */ 87 /* writeable short data sockets just have a tcp timeout */
81 if( !ws->keep_alive ) { 88 if( !ws->keep_alive ) {
@@ -152,12 +159,29 @@ ssize_t http_sendiovecdata( const int64 sock, struct ot_workstruct *ws, int iove
152 else 159 else
153 header_size = sprintf( header, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Length: %zd\r\n\r\n", size ); 160 header_size = sprintf( header, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Length: %zd\r\n\r\n", size );
154 161
155 iob_reset( &cookie->batch ); 162 if (!cookie->batch ) {
156 iob_addbuf_free( &cookie->batch, header, header_size ); 163 cookie->batch = malloc( sizeof(io_batch) );
164 memset( cookie->batch, 0, sizeof(io_batch) );
165 cookie->batches = 1;
166 }
167 iob_addbuf_free( cookie->batch, header, header_size );
168
169 /* Split huge iovectors into separate io_batches */
170 for( i=0; i<iovec_entries; ++i ) {
171 io_batch *current = cookie->batch + cookie->batches;
172
173 /* If the current batch's limit is reached, try to reallocate a new batch to work on */
174 if( current->bytesleft > OT_BATCH_LIMIT ) {
175 io_batch * new_batch = realloc( current, (cookie->batches + 1) * sizeof(io_batch) );
176 if( new_batch ) {
177 cookie->batches++;
178 current = cookie->batch = new_batch;
179 memset( current, 0, sizeof(io_batch) );
180 }
181 }
157 182
158 /* Will move to ot_iovec.c */ 183 iob_addbuf_munmap( current, iovector[i].iov_base, iovector[i].iov_len );
159 for( i=0; i<iovec_entries; ++i ) 184 }
160 iob_addbuf_munmap( &cookie->batch, iovector[i].iov_base, iovector[i].iov_len );
161 free( iovector ); 185 free( iovector );
162 186
163 /* writeable sockets timeout after 10 minutes */ 187 /* writeable sockets timeout after 10 minutes */