]> git.kaiwu.me - nginx.git/commitdiff
sendfile_max_chunk
authorIgor Sysoev <igor@sysoev.ru>
Mon, 7 May 2007 06:33:39 +0000 (06:33 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 7 May 2007 06:33:39 +0000 (06:33 +0000)
src/http/ngx_http_core_module.c
src/http/ngx_http_core_module.h
src/http/ngx_http_write_filter_module.c

index 76f5e9831c81a7ca725e118e1b076e2dde04c9d4..97f33f0f58ab95fd2b1ff8b881fe6a70e7f35e9e 100644 (file)
@@ -295,6 +295,13 @@ static ngx_command_t  ngx_http_core_commands[] = {
       offsetof(ngx_http_core_loc_conf_t, sendfile),
       NULL },
 
+    { ngx_string("sendfile_max_chunk"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_size_slot,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      offsetof(ngx_http_core_loc_conf_t, sendfile_max_chunk),
+      NULL },
+
     { ngx_string("tcp_nopush"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
       ngx_conf_set_flag_slot,
@@ -2191,6 +2198,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
     lcf->internal = NGX_CONF_UNSET;
     lcf->client_body_in_file_only = NGX_CONF_UNSET;
     lcf->sendfile = NGX_CONF_UNSET;
+    lcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE;
     lcf->tcp_nopush = NGX_CONF_UNSET;
     lcf->tcp_nodelay = NGX_CONF_UNSET;
     lcf->send_timeout = NGX_CONF_UNSET_MSEC;
@@ -2359,6 +2367,8 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
     ngx_conf_merge_value(conf->client_body_in_file_only,
                               prev->client_body_in_file_only, 0);
     ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
+    ngx_conf_merge_size_value(conf->sendfile_max_chunk,
+                              prev->sendfile_max_chunk, 0);
     ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
     ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1);
 
index bdb3a4a76a34ed9e61b585f8cb8be45356487b30..f9a64af90841fcba605b1f1dcd68e13ec7f17554 100644 (file)
@@ -245,6 +245,7 @@ struct ngx_http_core_loc_conf_s {
     size_t        send_lowat;              /* send_lowat */
     size_t        postpone_output;         /* postpone_output */
     size_t        limit_rate;              /* limit_rate */
+    size_t        sendfile_max_chunk;      /* sendfile_max_chunk */
 
     ngx_msec_t    client_body_timeout;     /* client_body_timeout */
     ngx_msec_t    send_timeout;            /* send_timeout */
index 21c1793b0543c5d93ac0d93b9472c14afd001bb5..944593ae4953e982706570ac3432796b0b73f494 100644 (file)
@@ -222,6 +222,9 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
             return NGX_AGAIN;
         }
 
+    } else if (clcf->sendfile_max_chunk) {
+        limit = clcf->sendfile_max_chunk;
+
     } else {
         limit = 0;
     }
@@ -241,10 +244,14 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
         return NGX_ERROR;
     }
 
-    if (limit) {
+    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 */) {