Mercurial > hg > nginx-quic
comparison src/http/ngx_http_write_filter.c @ 362:7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 21 Jun 2004 15:59:32 +0000 |
parents | 446782c909b3 |
children | f2755a2885c8 |
comparison
equal
deleted
inserted
replaced
361:446782c909b3 | 362:7650aea1816f |
---|---|
4 #include <ngx_event.h> | 4 #include <ngx_event.h> |
5 #include <ngx_http.h> | 5 #include <ngx_http.h> |
6 | 6 |
7 | 7 |
8 typedef struct { | 8 typedef struct { |
9 size_t postpone_output; | 9 size_t postpone_output; /* postpone_output */ |
10 size_t limit_rate; /* limit_rate */ | |
10 } ngx_http_write_filter_conf_t; | 11 } ngx_http_write_filter_conf_t; |
11 | 12 |
12 | 13 |
13 typedef struct { | 14 typedef struct { |
14 ngx_chain_t *out; | 15 ngx_chain_t *out; |
21 static ngx_int_t ngx_http_write_filter_init(ngx_cycle_t *cycle); | 22 static ngx_int_t ngx_http_write_filter_init(ngx_cycle_t *cycle); |
22 | 23 |
23 | 24 |
24 static ngx_command_t ngx_http_write_filter_commands[] = { | 25 static ngx_command_t ngx_http_write_filter_commands[] = { |
25 | 26 |
26 /* STUB */ | 27 { ngx_string("postpone_output"), |
27 { ngx_string("buffer_output"), | |
28 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 28 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
29 ngx_conf_set_size_slot, | 29 ngx_conf_set_size_slot, |
30 NGX_HTTP_LOC_CONF_OFFSET, | 30 NGX_HTTP_LOC_CONF_OFFSET, |
31 offsetof(ngx_http_write_filter_conf_t, postpone_output), | 31 offsetof(ngx_http_write_filter_conf_t, postpone_output), |
32 NULL }, | 32 NULL }, |
33 | 33 |
34 { ngx_string("postpone_output"), | 34 { ngx_string("limit_rate"), |
35 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 35 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
36 ngx_conf_set_size_slot, | 36 ngx_conf_set_size_slot, |
37 NGX_HTTP_LOC_CONF_OFFSET, | 37 NGX_HTTP_LOC_CONF_OFFSET, |
38 offsetof(ngx_http_write_filter_conf_t, postpone_output), | 38 offsetof(ngx_http_write_filter_conf_t, limit_rate), |
39 NULL }, | 39 NULL }, |
40 | 40 |
41 ngx_null_command | 41 ngx_null_command |
42 }; | 42 }; |
43 | 43 |
136 | 136 |
137 if (!last && flush == 0 && in && size < (off_t) conf->postpone_output) { | 137 if (!last && flush == 0 && in && size < (off_t) conf->postpone_output) { |
138 return NGX_OK; | 138 return NGX_OK; |
139 } | 139 } |
140 | 140 |
141 if (r->delayed) { | 141 if (r->connection->write->delayed) { |
142 return NGX_AGAIN; | 142 return NGX_AGAIN; |
143 } | 143 } |
144 | 144 |
145 if (size == 0) { | 145 if (size == 0) { |
146 if (!last) { | 146 if (!last) { |
150 return NGX_OK; | 150 return NGX_OK; |
151 } | 151 } |
152 | 152 |
153 sent = r->connection->sent; | 153 sent = r->connection->sent; |
154 | 154 |
155 chain = ngx_write_chain(r->connection, ctx->out); | 155 chain = ngx_write_chain(r->connection, ctx->out, |
156 conf->limit_rate ? conf->limit_rate: | |
157 OFF_T_MAX_VALUE); | |
156 | 158 |
157 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 159 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
158 "http write filter %X", chain); | 160 "http write filter %X", chain); |
159 | 161 |
160 #if 1 | 162 if (conf->limit_rate) { |
161 sent = r->connection->sent - sent; | 163 sent = r->connection->sent - sent; |
162 r->delayed = 1; | 164 r->connection->write->delayed = 1; |
163 ngx_add_timer(r->connection->write, sent * 1000 / (4 * 1024)); | 165 ngx_add_timer(r->connection->write, sent * 1000 / conf->limit_rate); |
164 #endif | 166 } |
165 | 167 |
166 if (chain == NGX_CHAIN_ERROR) { | 168 if (chain == NGX_CHAIN_ERROR) { |
167 return NGX_ERROR; | 169 return NGX_ERROR; |
168 } | 170 } |
169 | 171 |
184 ngx_test_null(conf, | 186 ngx_test_null(conf, |
185 ngx_palloc(cf->pool, sizeof(ngx_http_write_filter_conf_t)), | 187 ngx_palloc(cf->pool, sizeof(ngx_http_write_filter_conf_t)), |
186 NULL); | 188 NULL); |
187 | 189 |
188 conf->postpone_output = NGX_CONF_UNSET_SIZE; | 190 conf->postpone_output = NGX_CONF_UNSET_SIZE; |
191 conf->limit_rate = NGX_CONF_UNSET_SIZE; | |
189 | 192 |
190 return conf; | 193 return conf; |
191 } | 194 } |
192 | 195 |
193 | 196 |
198 ngx_http_write_filter_conf_t *conf = child; | 201 ngx_http_write_filter_conf_t *conf = child; |
199 | 202 |
200 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output, | 203 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output, |
201 1460); | 204 1460); |
202 | 205 |
206 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0); | |
207 | |
203 return NULL; | 208 return NULL; |
204 } | 209 } |
205 | 210 |
206 | 211 |
207 static ngx_int_t ngx_http_write_filter_init(ngx_cycle_t *cycle) | 212 static ngx_int_t ngx_http_write_filter_init(ngx_cycle_t *cycle) |