Mercurial > hg > nginx
annotate src/core/ngx_buf.c @ 8015:f669c9c2a617 stable-1.22 release-1.22.0
nginx-1.22.0-RELEASE
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 24 May 2022 02:59:18 +0300 |
parents | c7a8bdf5af55 |
children |
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) { | |
7282
da9941c9b01b
Leave chain in ngx_chain_add_copy() in consistent state on errors.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6874
diff
changeset
|
140 *ll = NULL; |
501 | 141 return NGX_ERROR; |
142 } | |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
143 |
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
|
144 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
|
145 *ll = cl; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
146 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
|
147 in = in->next; |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
148 } |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
149 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
150 *ll = NULL; |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
135
diff
changeset
|
151 |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
152 return NGX_OK; |
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 |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
132
diff
changeset
|
155 |
581 | 156 ngx_chain_t * |
157 ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free) | |
158 { | |
159 ngx_chain_t *cl; | |
160 | |
161 if (*free) { | |
162 cl = *free; | |
163 *free = cl->next; | |
164 cl->next = NULL; | |
165 return cl; | |
166 } | |
167 | |
168 cl = ngx_alloc_chain_link(p); | |
169 if (cl == NULL) { | |
170 return NULL; | |
171 } | |
172 | |
173 cl->buf = ngx_calloc_buf(p); | |
174 if (cl->buf == NULL) { | |
175 return NULL; | |
176 } | |
177 | |
178 cl->next = NULL; | |
179 | |
180 return cl; | |
181 } | |
182 | |
183 | |
499 | 184 void |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
185 ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free, ngx_chain_t **busy, |
499 | 186 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
|
187 { |
499 | 188 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
|
189 |
6797
40c2f3e06d23
Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents:
5915
diff
changeset
|
190 if (*out) { |
40c2f3e06d23
Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents:
5915
diff
changeset
|
191 if (*busy == NULL) { |
40c2f3e06d23
Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents:
5915
diff
changeset
|
192 *busy = *out; |
132
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
193 |
6797
40c2f3e06d23
Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents:
5915
diff
changeset
|
194 } else { |
40c2f3e06d23
Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents:
5915
diff
changeset
|
195 for (cl = *busy; cl->next; cl = cl->next) { /* void */ } |
455 | 196 |
6797
40c2f3e06d23
Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents:
5915
diff
changeset
|
197 cl->next = *out; |
40c2f3e06d23
Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents:
5915
diff
changeset
|
198 } |
40c2f3e06d23
Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents:
5915
diff
changeset
|
199 |
40c2f3e06d23
Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents:
5915
diff
changeset
|
200 *out = NULL; |
132
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
201 } |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
202 |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
203 while (*busy) { |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
204 cl = *busy; |
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
205 |
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
206 if (cl->buf->tag != tag) { |
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
207 *busy = cl->next; |
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
208 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
|
209 continue; |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
134
diff
changeset
|
210 } |
132
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
211 |
7951
c7a8bdf5af55
Changed ngx_chain_update_chains() to test tag first (ticket #2248).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7282
diff
changeset
|
212 if (ngx_buf_size(cl->buf) != 0) { |
c7a8bdf5af55
Changed ngx_chain_update_chains() to test tag first (ticket #2248).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7282
diff
changeset
|
213 break; |
c7a8bdf5af55
Changed ngx_chain_update_chains() to test tag first (ticket #2248).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7282
diff
changeset
|
214 } |
c7a8bdf5af55
Changed ngx_chain_update_chains() to test tag first (ticket #2248).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7282
diff
changeset
|
215 |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2414
diff
changeset
|
216 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
|
217 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
|
218 |
499 | 219 *busy = cl->next; |
220 cl->next = *free; | |
221 *free = cl; | |
132
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
222 } |
949f45d1589a
nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
223 } |
5850
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
224 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
225 |
5915
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
226 off_t |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
227 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
|
228 { |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
233 total = 0; |
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 cl = *in; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
236 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
|
237 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
238 do { |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
239 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
|
240 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
241 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
|
242 size = limit - total; |
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 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
|
245 & ~((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
|
246 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
247 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
|
248 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
|
249 } |
6874
7cc2d3a96ea3
Fixed trailer construction with limit on FreeBSD and macOS.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6797
diff
changeset
|
250 |
7cc2d3a96ea3
Fixed trailer construction with limit on FreeBSD and macOS.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6797
diff
changeset
|
251 total += size; |
7cc2d3a96ea3
Fixed trailer construction with limit on FreeBSD and macOS.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6797
diff
changeset
|
252 break; |
5915
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
253 } |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
254 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
255 total += size; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
256 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
|
257 cl = cl->next; |
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 } while (cl |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
260 && 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
|
261 && total < limit |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
262 && 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
|
263 && 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
|
264 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
265 *in = cl; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
266 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
267 return total; |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
268 } |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
269 |
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
270 |
5850
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
271 ngx_chain_t * |
5912
de68ed551bfb
Renamed ngx_handle_sent_chain() to ngx_chain_update_sent().
Valentin Bartenev <vbart@nginx.com>
parents:
5850
diff
changeset
|
272 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
|
273 { |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
274 off_t size; |
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 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
|
277 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
278 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
|
279 continue; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
280 } |
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 == 0) { |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
283 break; |
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 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
286 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
|
287 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
288 if (sent >= size) { |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
289 sent -= size; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
290 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
291 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
|
292 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
|
293 } |
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 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
|
296 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
|
297 } |
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 continue; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
300 } |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
301 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
302 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
|
303 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
|
304 } |
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 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
|
307 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
|
308 } |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
309 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
310 break; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
311 } |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
312 |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
313 return in; |
f9c83484d9ce
Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
314 } |