comparison src/http/ngx_http_write_filter_module.c @ 300:cba14c1e2a4b NGINX_0_5_20

nginx 0.5.20 *) Feature: the "sendfile_max_chunk" directive. *) Feature: the "$http_...", "$sent_http_...", and "$upstream_http_..." variables may be changed using the "set" directive. *) Bugfix: a segmentation fault might occur in worker process if the SSI command 'if expr="$var = /"' was used. *) Bugfix: trailing boundary of multipart range response was transferred incorrectly. Thanks to Evan Miller. *) Bugfix: nginx did not work on Solaris/sparc64 if it was built by Sun Studio. Thanks to Andrei Nigmatulin. *) Bugfix: the ngx_http_perl_module could not built by Solaris make. Thanks to Andrei Nigmatulin.
author Igor Sysoev <http://sysoev.ru>
date Mon, 07 May 2007 00:00:00 +0400
parents 30862655219e
children 7cf404023f50
comparison
equal deleted inserted replaced
299:7d0d14dc5fd7 300:cba14c1e2a4b
45 45
46 46
47 ngx_int_t 47 ngx_int_t
48 ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) 48 ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
49 { 49 {
50 off_t size, sent, to_send; 50 off_t size, sent, limit;
51 ngx_uint_t last, flush; 51 ngx_uint_t last, flush;
52 ngx_chain_t *cl, *ln, **ll, *chain; 52 ngx_chain_t *cl, *ln, **ll, *chain;
53 ngx_connection_t *c; 53 ngx_connection_t *c;
54 ngx_http_core_loc_conf_t *clcf; 54 ngx_http_core_loc_conf_t *clcf;
55 55
208 208
209 return NGX_ERROR; 209 return NGX_ERROR;
210 } 210 }
211 211
212 if (r->limit_rate) { 212 if (r->limit_rate) {
213 to_send = r->limit_rate * (ngx_time() - r->start_sec + 1) - c->sent; 213 limit = r->limit_rate * (ngx_time() - r->start_sec + 1) - c->sent;
214 214
215 if (to_send <= 0) { 215 if (limit <= 0) {
216 c->write->delayed = 1; 216 c->write->delayed = 1;
217 ngx_add_timer(c->write, 217 ngx_add_timer(c->write,
218 (ngx_msec_t) (- to_send * 1000 / r->limit_rate + 1)); 218 (ngx_msec_t) (- limit * 1000 / r->limit_rate + 1));
219 219
220 c->buffered |= NGX_HTTP_WRITE_BUFFERED; 220 c->buffered |= NGX_HTTP_WRITE_BUFFERED;
221 221
222 return NGX_AGAIN; 222 return NGX_AGAIN;
223 } 223 }
224 224
225 } else if (clcf->sendfile_max_chunk) {
226 limit = clcf->sendfile_max_chunk;
227
225 } else { 228 } else {
226 to_send = 0; 229 limit = 0;
227 } 230 }
228 231
229 sent = c->sent; 232 sent = c->sent;
230 233
231 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, 234 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
232 "http write filter to send %O", to_send); 235 "http write filter limit %O", limit);
233 236
234 chain = c->send_chain(c, r->out, to_send); 237 chain = c->send_chain(c, r->out, limit);
235 238
236 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, 239 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
237 "http write filter %p", chain); 240 "http write filter %p", chain);
238 241
239 if (chain == NGX_CHAIN_ERROR) { 242 if (chain == NGX_CHAIN_ERROR) {
240 c->error = 1; 243 c->error = 1;
241 return NGX_ERROR; 244 return NGX_ERROR;
242 } 245 }
243 246
244 if (to_send) { 247 if (r->limit_rate) {
245 sent = c->sent - sent; 248 sent = c->sent - sent;
246 c->write->delayed = 1; 249 c->write->delayed = 1;
247 ngx_add_timer(c->write, (ngx_msec_t) (sent * 1000 / r->limit_rate + 1)); 250 ngx_add_timer(c->write, (ngx_msec_t) (sent * 1000 / r->limit_rate + 1));
251
252 } else if (c->write->ready && clcf->sendfile_max_chunk) {
253 c->write->delayed = 1;
254 ngx_add_timer(c->write, 1);
248 } 255 }
249 256
250 for (cl = r->out; cl && cl != chain; /* void */) { 257 for (cl = r->out; cl && cl != chain; /* void */) {
251 ln = cl; 258 ln = cl;
252 cl = cl->next; 259 cl = cl->next;