comparison src/http/ngx_http_write_filter.c @ 395:f8f0f1834266

nginx-0.0.7-2004-07-16-21:11:43 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 16 Jul 2004 17:11:43 +0000
parents e7a68e14ccd3
children 6f3b20c1ac50
comparison
equal deleted inserted replaced
394:e7a68e14ccd3 395:f8f0f1834266
5 #include <ngx_http.h> 5 #include <ngx_http.h>
6 6
7 7
8 typedef struct { 8 typedef struct {
9 ngx_chain_t *out; 9 ngx_chain_t *out;
10
11 /* unsigned flush:1; */
12 ngx_uint_t flush;
10 } ngx_http_write_filter_ctx_t; 13 } ngx_http_write_filter_ctx_t;
11 14
12 15
13 static ngx_int_t ngx_http_write_filter_init(ngx_cycle_t *cycle); 16 static ngx_int_t ngx_http_write_filter_init(ngx_cycle_t *cycle);
14 17
40 ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) 43 ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
41 { 44 {
42 int last; 45 int last;
43 off_t size, flush, sent; 46 off_t size, flush, sent;
44 ngx_chain_t *cl, *ln, **ll, *chain; 47 ngx_chain_t *cl, *ln, **ll, *chain;
45 ngx_http_core_srv_conf_t *cscf;
46 ngx_http_core_loc_conf_t *clcf; 48 ngx_http_core_loc_conf_t *clcf;
47 ngx_http_write_filter_ctx_t *ctx; 49 ngx_http_write_filter_ctx_t *ctx;
48 50
49 ctx = ngx_http_get_module_ctx(r->main ? r->main : r, 51 ctx = ngx_http_get_module_ctx(r->main ? r->main : r,
50 ngx_http_write_filter_module); 52 ngx_http_write_filter_module);
112 114
113 if (r->connection->write->delayed) { 115 if (r->connection->write->delayed) {
114 return NGX_AGAIN; 116 return NGX_AGAIN;
115 } 117 }
116 118
117 if (size == 0) { 119 if (size == 0 && !ctx->flush) {
118 if (!last) { 120 if (!last) {
119 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 121 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
120 "the http output chain is empty"); 122 "the http output chain is empty");
121 } 123 }
122 return NGX_OK; 124 return NGX_OK;
123 } 125 }
124 126
125 sent = r->connection->sent; 127 sent = r->connection->sent;
126 128
127 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); 129 chain = r->send_chain(r->connection, ctx->out,
128 130 clcf->limit_rate ? clcf->limit_rate: OFF_T_MAX_VALUE);
129 chain = cscf->send_chain(r->connection, ctx->out,
130 clcf->limit_rate ? clcf->limit_rate:
131 OFF_T_MAX_VALUE);
132 131
133 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 132 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
134 "http write filter %X", chain); 133 "http write filter %X", chain);
135 134
136 if (clcf->limit_rate) { 135 if (clcf->limit_rate) {
140 (ngx_msec_t) (sent * 1000 / clcf->limit_rate)); 139 (ngx_msec_t) (sent * 1000 / clcf->limit_rate));
141 } 140 }
142 141
143 if (chain == NGX_CHAIN_ERROR) { 142 if (chain == NGX_CHAIN_ERROR) {
144 return NGX_ERROR; 143 return NGX_ERROR;
144 }
145
146 if (chain == NGX_CHAIN_AGAIN) {
147 ctx->out = NULL;
148 ctx->flush = 1;
149 return NGX_AGAIN;
145 } 150 }
146 151
147 ctx->out = chain; 152 ctx->out = chain;
148 153
149 if (chain == NULL) { 154 if (chain == NULL) {