diff 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
line wrap: on
line diff
--- a/src/http/ngx_http_write_filter_module.c
+++ b/src/http/ngx_http_write_filter_module.c
@@ -47,7 +47,7 @@ ngx_module_t  ngx_http_write_filter_modu
 ngx_int_t
 ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
 {
-    off_t                      size, sent, to_send;
+    off_t                      size, sent, limit;
     ngx_uint_t                 last, flush;
     ngx_chain_t               *cl, *ln, **ll, *chain;
     ngx_connection_t          *c;
@@ -210,28 +210,31 @@ ngx_http_write_filter(ngx_http_request_t
     }
 
     if (r->limit_rate) {
-        to_send = r->limit_rate * (ngx_time() - r->start_sec + 1) - c->sent;
+        limit = r->limit_rate * (ngx_time() - r->start_sec + 1) - c->sent;
 
-        if (to_send <= 0) {
+        if (limit <= 0) {
             c->write->delayed = 1;
             ngx_add_timer(c->write,
-                          (ngx_msec_t) (- to_send * 1000 / r->limit_rate + 1));
+                          (ngx_msec_t) (- limit * 1000 / r->limit_rate + 1));
 
             c->buffered |= NGX_HTTP_WRITE_BUFFERED;
 
             return NGX_AGAIN;
         }
 
+    } else if (clcf->sendfile_max_chunk) {
+        limit = clcf->sendfile_max_chunk;
+
     } else {
-        to_send = 0;
+        limit = 0;
     }
 
     sent = c->sent;
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
-                   "http write filter to send %O", to_send);
+                   "http write filter limit %O", limit);
 
-    chain = c->send_chain(c, r->out, to_send);
+    chain = c->send_chain(c, r->out, limit);
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http write filter %p", chain);
@@ -241,10 +244,14 @@ ngx_http_write_filter(ngx_http_request_t
         return NGX_ERROR;
     }
 
-    if (to_send) {
+    if (r->limit_rate) {
         sent = c->sent - sent;
         c->write->delayed = 1;
         ngx_add_timer(c->write, (ngx_msec_t) (sent * 1000 / r->limit_rate + 1));
+
+    } else if (c->write->ready && clcf->sendfile_max_chunk) {
+        c->write->delayed = 1;
+        ngx_add_timer(c->write, 1);
     }
 
     for (cl = r->out; cl && cl != chain; /* void */) {