Mercurial > hg > nginx-quic
annotate src/http/ngx_http_write_filter_module.c @ 4160:88369902edb1 stable-1.0
Merging r4010, r4065:
SSL related fixes:
*) Fixing proxy_set_body and proxy_pass_request_body with SSL.
Flush flag wasn't set in constructed buffer and this prevented any data
from being actually sent to upstream due to SSL buffering. Make sure
we always set flush in the last buffer we are going to sent.
See here for report:
http://nginx.org/pipermail/nginx-ru/2011-June/041552.html
*) Proper SSL shutdown handling.
If connection has unsent alerts, SSL_shutdown() tries to send them even
if SSL_set_shutdown(SSL_RECEIVED_SHUTDOWN|SSL_SENT_SHUTDOWN) was used.
This can be prevented by SSL_set_quiet_shutdown(). SSL_set_shutdown()
is required nevertheless to preserve session.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 30 Sep 2011 13:42:59 +0000 |
parents | 4f5753877376 |
children | 5130c16a130e 41b2d17534c1 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
403
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
403
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
403
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
403
diff
changeset
|
5 |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
8 #include <ngx_core.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
9 #include <ngx_http.h> |
43
53cd05892261
nginx-0.0.1-2002-12-27-19:22:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
42
diff
changeset
|
10 |
53cd05892261
nginx-0.0.1-2002-12-27-19:22:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
42
diff
changeset
|
11 |
681 | 12 static ngx_int_t ngx_http_write_filter_init(ngx_conf_t *cf); |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
9
diff
changeset
|
13 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
14 |
667 | 15 static ngx_http_module_t ngx_http_write_filter_module_ctx = { |
509 | 16 NULL, /* preconfiguration */ |
681 | 17 ngx_http_write_filter_init, /* postconfiguration */ |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
18 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
19 NULL, /* create main configuration */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
20 NULL, /* init main configuration */ |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
67
diff
changeset
|
21 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
22 NULL, /* create server configuration */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
23 NULL, /* merge server configuration */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
24 |
391
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
363
diff
changeset
|
25 NULL, /* create location configuration */ |
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
363
diff
changeset
|
26 NULL, /* merge location configuration */ |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
9
diff
changeset
|
27 }; |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 |
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 |
41
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
30 ngx_module_t ngx_http_write_filter_module = { |
509 | 31 NGX_MODULE_V1, |
90
37530da31268
nginx-0.0.1-2003-05-16-19:27:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
32 &ngx_http_write_filter_module_ctx, /* module context */ |
391
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
363
diff
changeset
|
33 NULL, /* module directives */ |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
34 NGX_HTTP_MODULE, /* module type */ |
541 | 35 NULL, /* init master */ |
681 | 36 NULL, /* init module */ |
541 | 37 NULL, /* init process */ |
38 NULL, /* init thread */ | |
39 NULL, /* exit thread */ | |
40 NULL, /* exit process */ | |
41 NULL, /* exit master */ | |
42 NGX_MODULE_V1_PADDING | |
41
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
43 }; |
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
44 |
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
45 |
501 | 46 ngx_int_t |
47 ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 { |
2907 | 49 off_t size, sent, nsent, limit; |
509 | 50 ngx_uint_t last, flush; |
1657
6a8a066adc98
improve throughput with large limit_rate
Igor Sysoev <igor@sysoev.ru>
parents:
1412
diff
changeset
|
51 ngx_msec_t delay; |
509 | 52 ngx_chain_t *cl, *ln, **ll, *chain; |
53 ngx_connection_t *c; | |
54 ngx_http_core_loc_conf_t *clcf; | |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
55 |
527 | 56 c = r->connection; |
57 | |
583 | 58 if (c->error) { |
527 | 59 return NGX_ERROR; |
60 } | |
61 | |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
62 size = 0; |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
63 flush = 0; |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 last = 0; |
509 | 65 ll = &r->out; |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
66 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
67 /* find the size, the flush point and the last link of the saved chain */ |
71
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
68 |
509 | 69 for (cl = r->out; cl; cl = cl->next) { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
70 ll = &cl->next; |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
71 |
667 | 72 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, c->log, 0, |
479 | 73 "write old buf t:%d f:%d %p, pos %p, size: %z " |
74 "file: %O, size: %z", | |
75 cl->buf->temporary, cl->buf->in_file, | |
76 cl->buf->start, cl->buf->pos, | |
77 cl->buf->last - cl->buf->pos, | |
78 cl->buf->file_pos, | |
79 cl->buf->file_last - cl->buf->file_pos); | |
80 | |
461 | 81 #if 1 |
82 if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) { | |
667 | 83 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
483 | 84 "zero size buf in writer " |
85 "t:%d r:%d f:%d %p %p-%p %p %O-%O", | |
86 cl->buf->temporary, | |
87 cl->buf->recycled, | |
88 cl->buf->in_file, | |
89 cl->buf->start, | |
90 cl->buf->pos, | |
91 cl->buf->last, | |
92 cl->buf->file, | |
93 cl->buf->file_pos, | |
94 cl->buf->file_last); | |
95 | |
461 | 96 ngx_debug_point(); |
489 | 97 return NGX_ERROR; |
461 | 98 } |
99 #endif | |
100 | |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
333
diff
changeset
|
101 size += ngx_buf_size(cl->buf); |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
102 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
333
diff
changeset
|
103 if (cl->buf->flush || cl->buf->recycled) { |
499 | 104 flush = 1; |
41
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
105 } |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
333
diff
changeset
|
107 if (cl->buf->last_buf) { |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
108 last = 1; |
41
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
109 } |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 } |
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 |
153
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
112 /* add the new chain to the existent one */ |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
113 |
332
159dd60d257a
nginx-0.0.3-2004-05-10-23:53:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
319
diff
changeset
|
114 for (ln = in; ln; ln = ln->next) { |
501 | 115 cl = ngx_alloc_chain_link(r->pool); |
116 if (cl == NULL) { | |
461 | 117 return NGX_ERROR; |
118 } | |
119 | |
120 cl->buf = ln->buf; | |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
121 *ll = cl; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
122 ll = &cl->next; |
153
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
123 |
667 | 124 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, c->log, 0, |
479 | 125 "write new buf t:%d f:%d %p, pos %p, size: %z " |
126 "file: %O, size: %z", | |
127 cl->buf->temporary, cl->buf->in_file, | |
128 cl->buf->start, cl->buf->pos, | |
129 cl->buf->last - cl->buf->pos, | |
130 cl->buf->file_pos, | |
131 cl->buf->file_last - cl->buf->file_pos); | |
132 | |
461 | 133 #if 1 |
134 if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) { | |
667 | 135 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
483 | 136 "zero size buf in writer " |
137 "t:%d r:%d f:%d %p %p-%p %p %O-%O", | |
138 cl->buf->temporary, | |
139 cl->buf->recycled, | |
140 cl->buf->in_file, | |
141 cl->buf->start, | |
142 cl->buf->pos, | |
143 cl->buf->last, | |
144 cl->buf->file, | |
145 cl->buf->file_pos, | |
146 cl->buf->file_last); | |
147 | |
461 | 148 ngx_debug_point(); |
489 | 149 return NGX_ERROR; |
461 | 150 } |
151 #endif | |
152 | |
403
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
153 size += ngx_buf_size(cl->buf); |
153
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
154 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
333
diff
changeset
|
155 if (cl->buf->flush || cl->buf->recycled) { |
499 | 156 flush = 1; |
153
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
157 } |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
158 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
333
diff
changeset
|
159 if (cl->buf->last_buf) { |
153
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
160 last = 1; |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
161 } |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
162 } |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
163 |
461 | 164 *ll = NULL; |
165 | |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
395
diff
changeset
|
166 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, |
499 | 167 "http write filter: l:%d f:%d s:%O", last, flush, size); |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
168 |
509 | 169 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
154
eac26585476e
nginx-0.0.1-2003-10-22-11:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
170 |
142
cb77c084acdb
nginx-0.0.1-2003-10-09-11:00:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
171 /* |
509 | 172 * avoid the output if there are no last buf, no flush point, |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
173 * there are the incoming bufs and the size of all bufs |
332
159dd60d257a
nginx-0.0.3-2004-05-10-23:53:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
319
diff
changeset
|
174 * is smaller than "postpone_output" directive |
142
cb77c084acdb
nginx-0.0.1-2003-10-09-11:00:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
175 */ |
71
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
176 |
499 | 177 if (!last && !flush && in && size < (off_t) clcf->postpone_output) { |
4
c5f071d376e5
nginx-0.0.1-2002-08-22-19:24:03 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
178 return NGX_OK; |
41
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
179 } |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
395
diff
changeset
|
181 if (c->write->delayed) { |
597 | 182 c->buffered |= NGX_HTTP_WRITE_BUFFERED; |
77
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
183 return NGX_AGAIN; |
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
184 } |
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
185 |
597 | 186 if (size == 0 && !(c->buffered & NGX_LOWLEVEL_BUFFERED)) { |
483 | 187 if (last) { |
509 | 188 r->out = NULL; |
597 | 189 c->buffered &= ~NGX_HTTP_WRITE_BUFFERED; |
190 | |
483 | 191 return NGX_OK; |
192 } | |
461 | 193 |
499 | 194 if (flush) { |
501 | 195 do { |
509 | 196 r->out = r->out->next; |
597 | 197 } while (r->out); |
198 | |
199 c->buffered &= ~NGX_HTTP_WRITE_BUFFERED; | |
501 | 200 |
499 | 201 return NGX_OK; |
202 } | |
203 | |
667 | 204 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
483 | 205 "the http output chain is empty"); |
461 | 206 |
483 | 207 ngx_debug_point(); |
208 | |
209 return NGX_ERROR; | |
143
5526213be452
nginx-0.0.1-2003-10-10-19:10:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
142
diff
changeset
|
210 } |
5526213be452
nginx-0.0.1-2003-10-10-19:10:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
142
diff
changeset
|
211 |
635 | 212 if (r->limit_rate) { |
2907 | 213 limit = r->limit_rate * (ngx_time() - r->start_sec + 1) |
214 - (c->sent - clcf->limit_rate_after); | |
633 | 215 |
1194
8ea6caa62c89
style fix: change variable name
Igor Sysoev <igor@sysoev.ru>
parents:
1179
diff
changeset
|
216 if (limit <= 0) { |
635 | 217 c->write->delayed = 1; |
667 | 218 ngx_add_timer(c->write, |
1194
8ea6caa62c89
style fix: change variable name
Igor Sysoev <igor@sysoev.ru>
parents:
1179
diff
changeset
|
219 (ngx_msec_t) (- limit * 1000 / r->limit_rate + 1)); |
635 | 220 |
221 c->buffered |= NGX_HTTP_WRITE_BUFFERED; | |
222 | |
223 return NGX_AGAIN; | |
224 } | |
225 | |
1197 | 226 } else if (clcf->sendfile_max_chunk) { |
227 limit = clcf->sendfile_max_chunk; | |
228 | |
635 | 229 } else { |
1194
8ea6caa62c89
style fix: change variable name
Igor Sysoev <igor@sysoev.ru>
parents:
1179
diff
changeset
|
230 limit = 0; |
633 | 231 } |
232 | |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
395
diff
changeset
|
233 sent = c->sent; |
361
446782c909b3
nginx-0.0.7-2004-06-20-23:54:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
234 |
633 | 235 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
1194
8ea6caa62c89
style fix: change variable name
Igor Sysoev <igor@sysoev.ru>
parents:
1179
diff
changeset
|
236 "http write filter limit %O", limit); |
633 | 237 |
1194
8ea6caa62c89
style fix: change variable name
Igor Sysoev <igor@sysoev.ru>
parents:
1179
diff
changeset
|
238 chain = c->send_chain(c, r->out, limit); |
61
4f3e2abcc2c4
nginx-0.0.1-2003-02-11-19:42:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
59
diff
changeset
|
239 |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
395
diff
changeset
|
240 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
461 | 241 "http write filter %p", chain); |
61
4f3e2abcc2c4
nginx-0.0.1-2003-02-11-19:42:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
59
diff
changeset
|
242 |
633 | 243 if (chain == NGX_CHAIN_ERROR) { |
244 c->error = 1; | |
245 return NGX_ERROR; | |
246 } | |
247 | |
1197 | 248 if (r->limit_rate) { |
2907 | 249 |
250 nsent = c->sent; | |
251 | |
252 if (clcf->limit_rate_after) { | |
253 | |
254 sent -= clcf->limit_rate_after; | |
255 if (sent < 0) { | |
256 sent = 0; | |
257 } | |
258 | |
259 nsent -= clcf->limit_rate_after; | |
260 if (nsent < 0) { | |
261 nsent = 0; | |
262 } | |
263 } | |
264 | |
265 delay = (ngx_msec_t) ((nsent - sent) * 1000 / r->limit_rate + 1); | |
1657
6a8a066adc98
improve throughput with large limit_rate
Igor Sysoev <igor@sysoev.ru>
parents:
1412
diff
changeset
|
266 |
6a8a066adc98
improve throughput with large limit_rate
Igor Sysoev <igor@sysoev.ru>
parents:
1412
diff
changeset
|
267 if (delay > 0) { |
6a8a066adc98
improve throughput with large limit_rate
Igor Sysoev <igor@sysoev.ru>
parents:
1412
diff
changeset
|
268 c->write->delayed = 1; |
6a8a066adc98
improve throughput with large limit_rate
Igor Sysoev <igor@sysoev.ru>
parents:
1412
diff
changeset
|
269 ngx_add_timer(c->write, delay); |
6a8a066adc98
improve throughput with large limit_rate
Igor Sysoev <igor@sysoev.ru>
parents:
1412
diff
changeset
|
270 } |
1197 | 271 |
1408
e67ef50c3176
set delay only when almost whole sendfile_max_chunk was transferred
Igor Sysoev <igor@sysoev.ru>
parents:
1197
diff
changeset
|
272 } else if (c->write->ready |
e67ef50c3176
set delay only when almost whole sendfile_max_chunk was transferred
Igor Sysoev <igor@sysoev.ru>
parents:
1197
diff
changeset
|
273 && clcf->sendfile_max_chunk |
1412 | 274 && (size_t) (c->sent - sent) |
1657
6a8a066adc98
improve throughput with large limit_rate
Igor Sysoev <igor@sysoev.ru>
parents:
1412
diff
changeset
|
275 >= clcf->sendfile_max_chunk - 2 * ngx_pagesize) |
1408
e67ef50c3176
set delay only when almost whole sendfile_max_chunk was transferred
Igor Sysoev <igor@sysoev.ru>
parents:
1197
diff
changeset
|
276 { |
1197 | 277 c->write->delayed = 1; |
278 ngx_add_timer(c->write, 1); | |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
361
diff
changeset
|
279 } |
361
446782c909b3
nginx-0.0.7-2004-06-20-23:54:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
280 |
509 | 281 for (cl = r->out; cl && cl != chain; /* void */) { |
507 | 282 ln = cl; |
283 cl = cl->next; | |
284 ngx_free_chain(r->pool, ln); | |
285 } | |
286 | |
509 | 287 r->out = chain; |
399
4e21d1291a14
nginx-0.0.7-2004-07-25-22:34:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
288 |
597 | 289 if (chain) { |
290 c->buffered |= NGX_HTTP_WRITE_BUFFERED; | |
291 return NGX_AGAIN; | |
292 } | |
293 | |
294 c->buffered &= ~NGX_HTTP_WRITE_BUFFERED; | |
295 | |
296 if ((c->buffered & NGX_LOWLEVEL_BUFFERED) && r->postponed == NULL) { | |
395
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
297 return NGX_AGAIN; |
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
298 } |
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
299 |
399
4e21d1291a14
nginx-0.0.7-2004-07-25-22:34:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
300 return NGX_OK; |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
301 } |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
302 |
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
303 |
501 | 304 static ngx_int_t |
681 | 305 ngx_http_write_filter_init(ngx_conf_t *cf) |
71
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
306 { |
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
307 ngx_http_top_body_filter = ngx_http_write_filter; |
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
308 |
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
309 return NGX_OK; |
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
310 } |