Mercurial > hg > nginx-quic
annotate src/http/ngx_http_write_filter_module.c @ 8945:043006e5a0b1
SSL: optimized rotation of session ticket keys.
Instead of syncing keys with shared memory on each ticket operation,
the code now does this only when the worker is going to change expiration
of the current key, or going to switch to a new key: that is, usually
at most once per second.
To do so without races, the code maintains 3 keys: current, previous,
and next. If a worker will switch to the next key earlier, other workers
will still be able to decrypt new tickets, since they will be encrypted
with the next key.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 12 Oct 2022 20:14:55 +0300 |
parents | 32b0ba4855a6 |
children | ce6d9cf0f567 |
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 |
4412 | 4 * Copyright (C) Nginx, Inc. |
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
|
5 */ |
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
|
6 |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #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
|
9 #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
|
10 #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
|
11 |
53cd05892261
nginx-0.0.1-2002-12-27-19:22:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
42
diff
changeset
|
12 |
681 | 13 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
|
14 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
15 |
667 | 16 static ngx_http_module_t ngx_http_write_filter_module_ctx = { |
509 | 17 NULL, /* preconfiguration */ |
681 | 18 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
|
19 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
20 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
|
21 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
|
22 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
23 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
|
24 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
|
25 |
391
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
363
diff
changeset
|
26 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
|
27 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
|
28 }; |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 |
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
30 |
41
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
31 ngx_module_t ngx_http_write_filter_module = { |
509 | 32 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
|
33 &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
|
34 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
|
35 NGX_HTTP_MODULE, /* module type */ |
541 | 36 NULL, /* init master */ |
681 | 37 NULL, /* init module */ |
541 | 38 NULL, /* init process */ |
39 NULL, /* init thread */ | |
40 NULL, /* exit thread */ | |
41 NULL, /* exit process */ | |
42 NULL, /* exit master */ | |
43 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
|
44 }; |
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
45 |
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
46 |
501 | 47 ngx_int_t |
48 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
|
49 { |
2907 | 50 off_t size, sent, nsent, limit; |
5926
08bfc7188a41
Write filter: fixed handling of sync bufs (ticket #132).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5884
diff
changeset
|
51 ngx_uint_t last, flush, sync; |
1657
6a8a066adc98
improve throughput with large limit_rate
Igor Sysoev <igor@sysoev.ru>
parents:
1412
diff
changeset
|
52 ngx_msec_t delay; |
509 | 53 ngx_chain_t *cl, *ln, **ll, *chain; |
54 ngx_connection_t *c; | |
55 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
|
56 |
527 | 57 c = r->connection; |
58 | |
583 | 59 if (c->error) { |
527 | 60 return NGX_ERROR; |
61 } | |
62 | |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
63 size = 0; |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
64 flush = 0; |
5926
08bfc7188a41
Write filter: fixed handling of sync bufs (ticket #132).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5884
diff
changeset
|
65 sync = 0; |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
66 last = 0; |
509 | 67 ll = &r->out; |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
68 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
69 /* 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
|
70 |
509 | 71 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
|
72 ll = &cl->next; |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
73 |
667 | 74 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, c->log, 0, |
479 | 75 "write old buf t:%d f:%d %p, pos %p, size: %z " |
6044
b8926ba4d087
Format specifier fixed for file size of buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5926
diff
changeset
|
76 "file: %O, size: %O", |
479 | 77 cl->buf->temporary, cl->buf->in_file, |
78 cl->buf->start, cl->buf->pos, | |
79 cl->buf->last - cl->buf->pos, | |
80 cl->buf->file_pos, | |
81 cl->buf->file_last - cl->buf->file_pos); | |
82 | |
461 | 83 if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) { |
667 | 84 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
483 | 85 "zero size buf in writer " |
86 "t:%d r:%d f:%d %p %p-%p %p %O-%O", | |
87 cl->buf->temporary, | |
88 cl->buf->recycled, | |
89 cl->buf->in_file, | |
90 cl->buf->start, | |
91 cl->buf->pos, | |
92 cl->buf->last, | |
93 cl->buf->file, | |
94 cl->buf->file_pos, | |
95 cl->buf->file_last); | |
96 | |
461 | 97 ngx_debug_point(); |
489 | 98 return NGX_ERROR; |
461 | 99 } |
7401
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
100 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
101 if (ngx_buf_size(cl->buf) < 0) { |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
102 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
103 "negative size buf in writer " |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
104 "t:%d r:%d f:%d %p %p-%p %p %O-%O", |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
105 cl->buf->temporary, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
106 cl->buf->recycled, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
107 cl->buf->in_file, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
108 cl->buf->start, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
109 cl->buf->pos, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
110 cl->buf->last, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
111 cl->buf->file, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
112 cl->buf->file_pos, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
113 cl->buf->file_last); |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
114 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
115 ngx_debug_point(); |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
116 return NGX_ERROR; |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
117 } |
461 | 118 |
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
|
119 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
|
120 |
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
|
121 if (cl->buf->flush || cl->buf->recycled) { |
499 | 122 flush = 1; |
41
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
123 } |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
124 |
5926
08bfc7188a41
Write filter: fixed handling of sync bufs (ticket #132).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5884
diff
changeset
|
125 if (cl->buf->sync) { |
08bfc7188a41
Write filter: fixed handling of sync bufs (ticket #132).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5884
diff
changeset
|
126 sync = 1; |
08bfc7188a41
Write filter: fixed handling of sync bufs (ticket #132).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5884
diff
changeset
|
127 } |
08bfc7188a41
Write filter: fixed handling of sync bufs (ticket #132).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5884
diff
changeset
|
128 |
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
|
129 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
|
130 last = 1; |
41
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
131 } |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 } |
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 |
153
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
134 /* 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
|
135 |
332
159dd60d257a
nginx-0.0.3-2004-05-10-23:53:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
319
diff
changeset
|
136 for (ln = in; ln; ln = ln->next) { |
501 | 137 cl = ngx_alloc_chain_link(r->pool); |
138 if (cl == NULL) { | |
461 | 139 return NGX_ERROR; |
140 } | |
141 | |
142 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
|
143 *ll = cl; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
144 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
|
145 |
667 | 146 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, c->log, 0, |
479 | 147 "write new buf t:%d f:%d %p, pos %p, size: %z " |
6044
b8926ba4d087
Format specifier fixed for file size of buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5926
diff
changeset
|
148 "file: %O, size: %O", |
479 | 149 cl->buf->temporary, cl->buf->in_file, |
150 cl->buf->start, cl->buf->pos, | |
151 cl->buf->last - cl->buf->pos, | |
152 cl->buf->file_pos, | |
153 cl->buf->file_last - cl->buf->file_pos); | |
154 | |
461 | 155 if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) { |
667 | 156 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
483 | 157 "zero size buf in writer " |
158 "t:%d r:%d f:%d %p %p-%p %p %O-%O", | |
159 cl->buf->temporary, | |
160 cl->buf->recycled, | |
161 cl->buf->in_file, | |
162 cl->buf->start, | |
163 cl->buf->pos, | |
164 cl->buf->last, | |
165 cl->buf->file, | |
166 cl->buf->file_pos, | |
167 cl->buf->file_last); | |
168 | |
461 | 169 ngx_debug_point(); |
489 | 170 return NGX_ERROR; |
461 | 171 } |
7401
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
172 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
173 if (ngx_buf_size(cl->buf) < 0) { |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
174 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
175 "negative size buf in writer " |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
176 "t:%d r:%d f:%d %p %p-%p %p %O-%O", |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
177 cl->buf->temporary, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
178 cl->buf->recycled, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
179 cl->buf->in_file, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
180 cl->buf->start, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
181 cl->buf->pos, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
182 cl->buf->last, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
183 cl->buf->file, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
184 cl->buf->file_pos, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
185 cl->buf->file_last); |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
186 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
187 ngx_debug_point(); |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
188 return NGX_ERROR; |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
189 } |
461 | 190 |
403
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
191 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
|
192 |
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
|
193 if (cl->buf->flush || cl->buf->recycled) { |
499 | 194 flush = 1; |
153
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
195 } |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
196 |
5926
08bfc7188a41
Write filter: fixed handling of sync bufs (ticket #132).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5884
diff
changeset
|
197 if (cl->buf->sync) { |
08bfc7188a41
Write filter: fixed handling of sync bufs (ticket #132).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5884
diff
changeset
|
198 sync = 1; |
08bfc7188a41
Write filter: fixed handling of sync bufs (ticket #132).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5884
diff
changeset
|
199 } |
08bfc7188a41
Write filter: fixed handling of sync bufs (ticket #132).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5884
diff
changeset
|
200 |
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
|
201 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
|
202 last = 1; |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
203 } |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
204 } |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
205 |
461 | 206 *ll = NULL; |
207 | |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
395
diff
changeset
|
208 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, |
6480 | 209 "http write filter: l:%ui f:%ui 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
|
210 |
509 | 211 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
|
212 |
142
cb77c084acdb
nginx-0.0.1-2003-10-09-11:00:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
213 /* |
509 | 214 * 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
|
215 * 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
|
216 * 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
|
217 */ |
71
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
218 |
499 | 219 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
|
220 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
|
221 } |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
222 |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
395
diff
changeset
|
223 if (c->write->delayed) { |
597 | 224 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
|
225 return NGX_AGAIN; |
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
226 } |
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
227 |
5513
311803b21504
SPDY: body filter was replaced by c->send_chain() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5201
diff
changeset
|
228 if (size == 0 |
311803b21504
SPDY: body filter was replaced by c->send_chain() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5201
diff
changeset
|
229 && !(c->buffered & NGX_LOWLEVEL_BUFFERED) |
8843
32b0ba4855a6
HTTP/2: made it possible to flush response headers (ticket #1743).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8671
diff
changeset
|
230 && !(last && c->need_last_buf) |
32b0ba4855a6
HTTP/2: made it possible to flush response headers (ticket #1743).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8671
diff
changeset
|
231 && !(flush && c->need_flush_buf)) |
5513
311803b21504
SPDY: body filter was replaced by c->send_chain() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5201
diff
changeset
|
232 { |
5926
08bfc7188a41
Write filter: fixed handling of sync bufs (ticket #132).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5884
diff
changeset
|
233 if (last || flush || sync) { |
4833
3464d0b63300
Write filter: replaced unneeded loop with one to free chains.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
234 for (cl = r->out; cl; /* void */) { |
3464d0b63300
Write filter: replaced unneeded loop with one to free chains.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
235 ln = cl; |
3464d0b63300
Write filter: replaced unneeded loop with one to free chains.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
236 cl = cl->next; |
3464d0b63300
Write filter: replaced unneeded loop with one to free chains.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
237 ngx_free_chain(r->pool, ln); |
3464d0b63300
Write filter: replaced unneeded loop with one to free chains.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
238 } |
597 | 239 |
4833
3464d0b63300
Write filter: replaced unneeded loop with one to free chains.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
240 r->out = NULL; |
597 | 241 c->buffered &= ~NGX_HTTP_WRITE_BUFFERED; |
501 | 242 |
499 | 243 return NGX_OK; |
244 } | |
245 | |
667 | 246 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
483 | 247 "the http output chain is empty"); |
461 | 248 |
483 | 249 ngx_debug_point(); |
250 | |
251 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
|
252 } |
5526213be452
nginx-0.0.1-2003-10-10-19:10:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
142
diff
changeset
|
253 |
7504
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7401
diff
changeset
|
254 if (!r->limit_rate_set) { |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7401
diff
changeset
|
255 r->limit_rate = ngx_http_complex_value_size(r, clcf->limit_rate, 0); |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7401
diff
changeset
|
256 r->limit_rate_set = 1; |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7401
diff
changeset
|
257 } |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7401
diff
changeset
|
258 |
635 | 259 if (r->limit_rate) { |
7504
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7401
diff
changeset
|
260 |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7401
diff
changeset
|
261 if (!r->limit_rate_after_set) { |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7401
diff
changeset
|
262 r->limit_rate_after = ngx_http_complex_value_size(r, |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7401
diff
changeset
|
263 clcf->limit_rate_after, 0); |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7401
diff
changeset
|
264 r->limit_rate_after_set = 1; |
5201
06fbbde04098
Added r->limit_rate_after.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4961
diff
changeset
|
265 } |
06fbbde04098
Added r->limit_rate_after.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4961
diff
changeset
|
266 |
4961
ed576bd1d9c0
Limit rate: fixed integer overflow in limit calculation (ticket #256).
Valentin Bartenev <vbart@nginx.com>
parents:
4833
diff
changeset
|
267 limit = (off_t) r->limit_rate * (ngx_time() - r->start_sec + 1) |
5201
06fbbde04098
Added r->limit_rate_after.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4961
diff
changeset
|
268 - (c->sent - r->limit_rate_after); |
633 | 269 |
1194
8ea6caa62c89
style fix: change variable name
Igor Sysoev <igor@sysoev.ru>
parents:
1179
diff
changeset
|
270 if (limit <= 0) { |
635 | 271 c->write->delayed = 1; |
5884
8486205d10db
Write filter: stored delay in a variable, no functional changes.
Roman Arutyunyan <arut@nginx.com>
parents:
5513
diff
changeset
|
272 delay = (ngx_msec_t) (- limit * 1000 / r->limit_rate + 1); |
8486205d10db
Write filter: stored delay in a variable, no functional changes.
Roman Arutyunyan <arut@nginx.com>
parents:
5513
diff
changeset
|
273 ngx_add_timer(c->write, delay); |
635 | 274 |
275 c->buffered |= NGX_HTTP_WRITE_BUFFERED; | |
276 | |
277 return NGX_AGAIN; | |
278 } | |
279 | |
4384
a8b6d5dee539
Fixed interaction of limit_rate and sendfile_max_chunk.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4383
diff
changeset
|
280 if (clcf->sendfile_max_chunk |
a8b6d5dee539
Fixed interaction of limit_rate and sendfile_max_chunk.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4383
diff
changeset
|
281 && (off_t) clcf->sendfile_max_chunk < limit) |
a8b6d5dee539
Fixed interaction of limit_rate and sendfile_max_chunk.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4383
diff
changeset
|
282 { |
a8b6d5dee539
Fixed interaction of limit_rate and sendfile_max_chunk.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4383
diff
changeset
|
283 limit = clcf->sendfile_max_chunk; |
a8b6d5dee539
Fixed interaction of limit_rate and sendfile_max_chunk.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4383
diff
changeset
|
284 } |
1197 | 285 |
635 | 286 } else { |
4384
a8b6d5dee539
Fixed interaction of limit_rate and sendfile_max_chunk.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4383
diff
changeset
|
287 limit = clcf->sendfile_max_chunk; |
633 | 288 } |
289 | |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
395
diff
changeset
|
290 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
|
291 |
633 | 292 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
|
293 "http write filter limit %O", limit); |
633 | 294 |
1194
8ea6caa62c89
style fix: change variable name
Igor Sysoev <igor@sysoev.ru>
parents:
1179
diff
changeset
|
295 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
|
296 |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
395
diff
changeset
|
297 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
461 | 298 "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
|
299 |
633 | 300 if (chain == NGX_CHAIN_ERROR) { |
301 c->error = 1; | |
302 return NGX_ERROR; | |
303 } | |
304 | |
1197 | 305 if (r->limit_rate) { |
2907 | 306 |
307 nsent = c->sent; | |
308 | |
5201
06fbbde04098
Added r->limit_rate_after.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4961
diff
changeset
|
309 if (r->limit_rate_after) { |
2907 | 310 |
5201
06fbbde04098
Added r->limit_rate_after.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4961
diff
changeset
|
311 sent -= r->limit_rate_after; |
2907 | 312 if (sent < 0) { |
313 sent = 0; | |
314 } | |
315 | |
5201
06fbbde04098
Added r->limit_rate_after.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4961
diff
changeset
|
316 nsent -= r->limit_rate_after; |
2907 | 317 if (nsent < 0) { |
318 nsent = 0; | |
319 } | |
320 } | |
321 | |
4383
5130c16a130e
Fixed throughput problems with large limit_rate.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2907
diff
changeset
|
322 delay = (ngx_msec_t) ((nsent - sent) * 1000 / r->limit_rate); |
1657
6a8a066adc98
improve throughput with large limit_rate
Igor Sysoev <igor@sysoev.ru>
parents:
1412
diff
changeset
|
323 |
6a8a066adc98
improve throughput with large limit_rate
Igor Sysoev <igor@sysoev.ru>
parents:
1412
diff
changeset
|
324 if (delay > 0) { |
6a8a066adc98
improve throughput with large limit_rate
Igor Sysoev <igor@sysoev.ru>
parents:
1412
diff
changeset
|
325 c->write->delayed = 1; |
6a8a066adc98
improve throughput with large limit_rate
Igor Sysoev <igor@sysoev.ru>
parents:
1412
diff
changeset
|
326 ngx_add_timer(c->write, delay); |
6a8a066adc98
improve throughput with large limit_rate
Igor Sysoev <igor@sysoev.ru>
parents:
1412
diff
changeset
|
327 } |
4384
a8b6d5dee539
Fixed interaction of limit_rate and sendfile_max_chunk.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4383
diff
changeset
|
328 } |
1197 | 329 |
8671
51a260276425
Simplified sendfile_max_chunk handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8670
diff
changeset
|
330 if (chain && c->write->ready && !c->write->delayed) { |
8670
61e9c078ee3d
Switched to using posted next events after sendfile_max_chunk.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7504
diff
changeset
|
331 ngx_post_event(c->write, &ngx_posted_next_events); |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
361
diff
changeset
|
332 } |
361
446782c909b3
nginx-0.0.7-2004-06-20-23:54:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
333 |
509 | 334 for (cl = r->out; cl && cl != chain; /* void */) { |
507 | 335 ln = cl; |
336 cl = cl->next; | |
337 ngx_free_chain(r->pool, ln); | |
338 } | |
339 | |
509 | 340 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
|
341 |
597 | 342 if (chain) { |
343 c->buffered |= NGX_HTTP_WRITE_BUFFERED; | |
344 return NGX_AGAIN; | |
345 } | |
346 | |
347 c->buffered &= ~NGX_HTTP_WRITE_BUFFERED; | |
348 | |
349 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
|
350 return NGX_AGAIN; |
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
351 } |
f8f0f1834266
nginx-0.0.7-2004-07-16-21:11:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
394
diff
changeset
|
352 |
399
4e21d1291a14
nginx-0.0.7-2004-07-25-22:34:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
353 return NGX_OK; |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
354 } |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
355 |
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
356 |
501 | 357 static ngx_int_t |
681 | 358 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
|
359 { |
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
360 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
|
361 |
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
362 return NGX_OK; |
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
363 } |