Mercurial > hg > nginx
annotate src/core/ngx_buf.c @ 5992:174512857ccf
Cache: do not inherit last_modified and etag from stale response.
When replacing a stale cache entry, its last_modified and etag could be
inherited from the old entry if the response code is not 200 or 206. Moreover,
etag could be inherited with any response code if it's missing in the new
response. As a result, the cache entry is left with invalid last_modified or
etag which could lead to broken revalidation.
For example, when a file is deleted from backend, its last_modified is copied to
the new 404 cache entry and is used later for revalidation. Once the old file
appears again with its original timestamp, revalidation succeeds and the cached
404 response is sent to client instead of the file.
The problem appeared with etags in 44b9ab7752e3 (1.7.3) and affected
last_modified in 1573fc7875fa (1.7.9).
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Mon, 02 Mar 2015 19:47:13 +0300 |
parents | ac3f78219f85 |
children | 40c2f3e06d23 a3e6d660b179 |
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:
436
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:
436
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:
436
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:
436
diff
changeset
|
6 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
42
cd035a94e0b6
nginx-0.0.1-2002-12-27-10:27:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
8 #include <ngx_config.h> |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
9 #include <ngx_core.h> |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
499 | 12 ngx_buf_t * |
13 ngx_create_temp_buf(ngx_pool_t *pool, size_t size) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 { |
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:
290
diff
changeset
|
15 ngx_buf_t *b; |
16
6ce4755737b4
nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
16 |
501 | 17 b = ngx_calloc_buf(pool); |
18 if (b == NULL) { | |
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:
290
diff
changeset
|
19 return NULL; |
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:
290
diff
changeset
|
20 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
21 |
501 | 22 b->start = ngx_palloc(pool, size); |
23 if (b->start == NULL) { | |
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:
290
diff
changeset
|
24 return NULL; |
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:
290
diff
changeset
|
25 } |
166
389d7ee9fa60
nginx-0.0.1-2003-10-30-11:51:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
26 |
499 | 27 /* |
28 * set by ngx_calloc_buf(): | |
29 * | |
30 * b->file_pos = 0; | |
31 * b->file_last = 0; | |
32 * b->file = NULL; | |
33 * b->shadow = NULL; | |
34 * b->tag = 0; | |
509 | 35 * and flags |
499 | 36 */ |
37 | |
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:
290
diff
changeset
|
38 b->pos = b->start; |
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:
290
diff
changeset
|
39 b->last = b->start; |
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:
290
diff
changeset
|
40 b->end = b->last + size; |
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:
290
diff
changeset
|
41 b->temporary = 1; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 |
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:
290
diff
changeset
|
43 return b; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 } |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
76
diff
changeset
|
45 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
46 |
499 | 47 ngx_chain_t * |
507 | 48 ngx_alloc_chain_link(ngx_pool_t *pool) |
49 { | |
50 ngx_chain_t *cl; | |
51 | |
52 cl = pool->chain; | |
53 | |
54 if (cl) { | |
55 pool->chain = cl->next; | |
56 return cl; | |
57 } | |
58 | |
59 cl = ngx_palloc(pool, sizeof(ngx_chain_t)); | |
60 if (cl == NULL) { | |
61 return NULL; | |
62 } | |
63 | |
64 return cl; | |
65 } | |
66 | |
67 | |
68 ngx_chain_t * | |
499 | 69 ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs) |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
70 { |
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:
290
diff
changeset
|
71 u_char *p; |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
239
diff
changeset
|
72 ngx_int_t i; |
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:
290
diff
changeset
|
73 ngx_buf_t *b; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
74 ngx_chain_t *chain, *cl, **ll; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
75 |
501 | 76 p = ngx_palloc(pool, bufs->num * bufs->size); |
77 if (p == NULL) { | |
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:
290
diff
changeset
|
78 return NULL; |
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:
290
diff
changeset
|
79 } |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
80 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
81 ll = &chain; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
82 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
83 for (i = 0; i < bufs->num; i++) { |
501 | 84 |
85 b = ngx_calloc_buf(pool); | |
86 if (b == NULL) { | |
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:
290
diff
changeset
|
87 return NULL; |
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:
290
diff
changeset
|
88 } |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
89 |
499 | 90 /* |
91 * set by ngx_calloc_buf(): | |
92 * | |
93 * b->file_pos = 0; | |
94 * b->file_last = 0; | |
95 * b->file = NULL; | |
96 * b->shadow = NULL; | |
97 * b->tag = 0; | |
509 | 98 * and flags |
499 | 99 * |
100 */ | |
101 | |
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:
290
diff
changeset
|
102 b->pos = p; |
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:
290
diff
changeset
|
103 b->last = p; |
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:
290
diff
changeset
|
104 b->temporary = 1; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
105 |
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:
290
diff
changeset
|
106 b->start = p; |
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:
290
diff
changeset
|
107 p += bufs->size; |
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:
290
diff
changeset
|
108 b->end = p; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
109 |
501 | 110 cl = ngx_alloc_chain_link(pool); |
111 if (cl == NULL) { | |
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:
290
diff
changeset
|
112 return NULL; |
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:
290
diff
changeset
|
113 } |
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:
290
diff
changeset
|
114 |
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:
290
diff
changeset
|
115 cl->buf = b; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
116 *ll = cl; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
117 ll = &cl->next; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
118 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
119 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
120 *ll = NULL; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
121 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
122 return chain; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
123 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
124 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
125 |
499 | 126 ngx_int_t |
127 ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in) | |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
128 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
129 ngx_chain_t *cl, **ll; |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
130 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
131 ll = chain; |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
132 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
133 for (cl = *chain; cl; cl = cl->next) { |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
134 ll = &cl->next; |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
135 } |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
136 |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
137 while (in) { |
501 | 138 cl = ngx_alloc_chain_link(pool); |
139 if (cl == NULL) { | |
140 return NGX_ERROR; | |
141 } | |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
142 |
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:
290
diff
changeset
|
143 cl->buf = in->buf; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
144 *ll = cl; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
145 ll = &cl->next; |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
146 in = in->next; |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
147 } |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
148 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
149 *ll = NULL; |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
135
diff
changeset
|
150 |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
151 return NGX_OK; |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
152 } |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
153 |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
154 |
581 | 155 ngx_chain_t * |
156 ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free) | |
157 { | |
158 ngx_chain_t *cl; | |
159 | |
160 if (*free) { | |
161 cl = *free; | |
162 *free = cl->next; | |
163 cl->next = NULL; | |
164 return cl; | |
165 } | |
166 | |
167 cl = ngx_alloc_chain_link(p); | |
168 if (cl == NULL) { | |
169 return NULL; | |
170 } | |
171 | |
172 cl->buf = ngx_calloc_buf(p); | |
173 if (cl->buf == NULL) { | |
174 return NULL; | |
175 } | |
176 | |
177 cl->next = NULL; | |
178 | |
179 return cl; | |
180 } | |
181 | |
182 | |
499 | 183 void |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
184 ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free, ngx_chain_t **busy, |
499 | 185 ngx_chain_t **out, ngx_buf_tag_t tag) |
132
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
186 { |
499 | 187 ngx_chain_t *cl; |
132
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
188 |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
189 if (*busy == NULL) { |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
190 *busy = *out; |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
191 |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
192 } else { |
499 | 193 for (cl = *busy; cl->next; cl = cl->next) { /* void */ } |
455 | 194 |
499 | 195 cl->next = *out; |
132
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
196 } |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
197 |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
198 *out = NULL; |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
199 |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
200 while (*busy) { |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
201 cl = *busy; |
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
202 |
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
203 if (ngx_buf_size(cl->buf) != 0) { |
132
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
204 break; |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
205 } |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
206 |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
207 if (cl->buf->tag != tag) { |
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
208 *busy = cl->next; |
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
209 ngx_free_chain(p, cl); |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
134
diff
changeset
|
210 continue; |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
134
diff
changeset
|
211 } |
132
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
212 |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
213 cl->buf->pos = cl->buf->start; |
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
214 cl->buf->last = cl->buf->start; |
132
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
215 |
499 | 216 *busy = cl->next; |
217 cl->next = *free; | |
218 *free = cl; | |
132
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
219 } |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
220 } |
5850
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
221 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
222 |
5915
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
223 off_t |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
224 ngx_chain_coalesce_file(ngx_chain_t **in, off_t limit) |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
225 { |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
226 off_t total, size, aligned, fprev; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
227 ngx_fd_t fd; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
228 ngx_chain_t *cl; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
229 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
230 total = 0; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
231 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
232 cl = *in; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
233 fd = cl->buf->file->fd; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
234 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
235 do { |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
236 size = cl->buf->file_last - cl->buf->file_pos; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
237 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
238 if (size > limit - total) { |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
239 size = limit - total; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
240 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
241 aligned = (cl->buf->file_pos + size + ngx_pagesize - 1) |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
242 & ~((off_t) ngx_pagesize - 1); |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
243 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
244 if (aligned <= cl->buf->file_last) { |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
245 size = aligned - cl->buf->file_pos; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
246 } |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
247 } |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
248 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
249 total += size; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
250 fprev = cl->buf->file_pos + size; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
251 cl = cl->next; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
252 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
253 } while (cl |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
254 && cl->buf->in_file |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
255 && total < limit |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
256 && fd == cl->buf->file->fd |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
257 && fprev == cl->buf->file_pos); |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
258 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
259 *in = cl; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
260 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
261 return total; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
262 } |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
263 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
264 |
5850
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
265 ngx_chain_t * |
5912
de68ed551bfb
Renamed ngx_handle_sent_chain() to ngx_chain_update_sent().
Valentin Bartenev <vbart@nginx.com>
parents:
5850
diff
changeset
|
266 ngx_chain_update_sent(ngx_chain_t *in, off_t sent) |
5850
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
267 { |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
268 off_t size; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
269 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
270 for ( /* void */ ; in; in = in->next) { |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
271 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
272 if (ngx_buf_special(in->buf)) { |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
273 continue; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
274 } |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
275 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
276 if (sent == 0) { |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
277 break; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
278 } |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
279 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
280 size = ngx_buf_size(in->buf); |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
281 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
282 if (sent >= size) { |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
283 sent -= size; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
284 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
285 if (ngx_buf_in_memory(in->buf)) { |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
286 in->buf->pos = in->buf->last; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
287 } |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
288 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
289 if (in->buf->in_file) { |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
290 in->buf->file_pos = in->buf->file_last; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
291 } |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
292 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
293 continue; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
294 } |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
295 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
296 if (ngx_buf_in_memory(in->buf)) { |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
297 in->buf->pos += (size_t) sent; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
298 } |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
299 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
300 if (in->buf->in_file) { |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
301 in->buf->file_pos += sent; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
302 } |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
303 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
304 break; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
305 } |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
306 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
307 return in; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
308 } |