Mercurial > hg > nginx
comparison src/http/ngx_http_output_filter.c @ 62:8ccba41a678e
nginx-0.0.1-2003-02-12-09:55:42 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 12 Feb 2003 06:55:42 +0000 |
parents | 4f3e2abcc2c4 |
children | 5a7d1aaa1618 |
comparison
equal
deleted
inserted
replaced
61:4f3e2abcc2c4 | 62:8ccba41a678e |
---|---|
69 | 69 |
70 int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk) | 70 int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk) |
71 { | 71 { |
72 int rc; | 72 int rc; |
73 size_t size; | 73 size_t size; |
74 ngx_chain_t *ce, *pe; | 74 ngx_chain_t *ce, *le; |
75 ngx_http_output_filter_ctx_t *ctx; | 75 ngx_http_output_filter_ctx_t *ctx; |
76 ngx_http_output_filter_conf_t *conf; | 76 ngx_http_output_filter_conf_t *conf; |
77 | 77 |
78 ctx = (ngx_http_output_filter_ctx_t *) | 78 ctx = (ngx_http_output_filter_ctx_t *) |
79 ngx_http_get_module_ctx(r->main ? r->main : r, | 79 ngx_http_get_module_ctx(r->main ? r->main : r, |
94 | 94 |
95 /* we do not need to copy the incoming hunk to our hunk */ | 95 /* we do not need to copy the incoming hunk to our hunk */ |
96 if (!need_to_copy(r, hunk)) { | 96 if (!need_to_copy(r, hunk)) { |
97 ctx->out.hunk = hunk; | 97 ctx->out.hunk = hunk; |
98 ctx->out.next = NULL; | 98 ctx->out.next = NULL; |
99 | |
100 return next_filter(r, &ctx->out); | 99 return next_filter(r, &ctx->out); |
101 } | 100 } |
102 } | 101 } |
103 | 102 |
104 /* add the incoming hunk to the chain ctx->incoming */ | 103 /* add the incoming hunk to the chain ctx->incoming */ |
105 if (hunk) { | 104 if (hunk) { |
106 | 105 |
107 /* the output of the only hunk is common case so we have | 106 /* the output of the only hunk is common case so we have |
108 special chain entry ctx->in for it */ | 107 the special chain entry ctx->in for it */ |
109 if (ctx->incoming == NULL) { | 108 if (ctx->incoming == NULL) { |
110 ctx->in.hunk = hunk; | 109 ctx->in.hunk = hunk; |
111 ctx->in.next = NULL; | 110 ctx->in.next = NULL; |
112 ctx->incoming = &ctx->in; | 111 ctx->incoming = &ctx->in; |
113 | 112 |
114 } else { | 113 } else { |
115 for (ce = ctx->incoming; ce->next; ce = ce->next) { | 114 for (ce = ctx->incoming; ce->next; ce = ce->next) { /* void */ ; } |
116 /* void */ ; | |
117 } | |
118 | |
119 ngx_add_hunk_to_chain(ce->next, hunk, r->pool, NGX_ERROR); | 115 ngx_add_hunk_to_chain(ce->next, hunk, r->pool, NGX_ERROR); |
120 } | 116 } |
121 } | 117 } |
122 | 118 |
123 /* allocate our hunk if it's needed */ | 119 /* allocate our hunk if it's needed */ |
124 if (ctx->hunk == NULL) { | 120 if (ctx->hunk == NULL) { |
125 | 121 |
126 conf = (ngx_http_output_filter_conf_t *) | 122 conf = (ngx_http_output_filter_conf_t *) |
127 ngx_http_get_module_loc_conf(r->main ? r->main : r, | 123 ngx_http_get_module_loc_conf(r->main ? r->main : r, |
128 ngx_http_output_filter_module); | 124 ngx_http_output_filter_module); |
129 | 125 |
130 if (hunk->type & NGX_HUNK_LAST) { | 126 if (hunk->type & NGX_HUNK_LAST) { |
131 size = hunk->last.mem - hunk->pos.mem; | 127 size = hunk->last.mem - hunk->pos.mem; |
132 if (size > conf->hunk_size) { | 128 if (size > conf->hunk_size) { |
133 size = conf->hunk_size; | 129 size = conf->hunk_size; |
138 } | 134 } |
139 | 135 |
140 ngx_test_null(ctx->hunk, | 136 ngx_test_null(ctx->hunk, |
141 ngx_create_temp_hunk(r->pool, size, 50, 50), | 137 ngx_create_temp_hunk(r->pool, size, 50, 50), |
142 NGX_ERROR); | 138 NGX_ERROR); |
143 | |
144 ctx->hunk->type |= NGX_HUNK_RECYCLED; | 139 ctx->hunk->type |= NGX_HUNK_RECYCLED; |
145 | 140 |
146 | 141 |
147 /* our hunk is still busy */ | 142 /* our hunk is still busy */ |
148 } else if (ctx->hunk->pos.mem < ctx->hunk->last.mem) { | 143 } else if (ctx->hunk->pos.mem < ctx->hunk->last.mem) { |
151 if (rc == NGX_ERROR || rc == NGX_AGAIN) { | 146 if (rc == NGX_ERROR || rc == NGX_AGAIN) { |
152 return rc; | 147 return rc; |
153 } | 148 } |
154 | 149 |
155 /* NGX_OK */ | 150 /* NGX_OK */ |
156 | |
157 /* set our hunk free */ | 151 /* set our hunk free */ |
158 ctx->hunk->pos.mem = ctx->hunk->last.mem = ctx->hunk->start; | 152 ctx->hunk->pos.mem = ctx->hunk->last.mem = ctx->hunk->start; |
159 } | 153 } |
160 | 154 |
161 #if (NGX_SUPPRESS_WARN) | 155 #if (NGX_SUPPRESS_WARN) |
162 pe = NULL; | 156 le = NULL; |
163 #endif | 157 #endif |
164 | 158 |
165 /* process the chain ctx->incoming */ | 159 /* process the chain ctx->incoming */ |
166 do { | 160 do { |
167 /* find the hunks that do not need to be copied ... */ | 161 /* find the hunks that do not need to be copied ... */ |
168 for (ce = ctx->incoming; ce; ce = ce->next) { | 162 for (ce = ctx->incoming; ce; ce = ce->next) { |
169 if (need_to_copy(r, ce->hunk)) { | 163 if (need_to_copy(r, ce->hunk)) { |
170 break; | 164 break; |
171 } | 165 } |
172 pe = ce; | 166 le = ce; |
173 } | 167 } |
174 | 168 |
175 /* ... and pass them to the next filter */ | 169 /* ... and pass them to the next filter */ |
176 if (ctx->incoming != ce) { | 170 if (ctx->incoming != ce) { |
177 | 171 |
178 ctx->out.hunk = ctx->incoming->hunk; | 172 ctx->out.hunk = ctx->incoming->hunk; |
179 ctx->out.next = ctx->incoming->next; | 173 ctx->out.next = ctx->incoming->next; |
180 ctx->incoming = ce; | 174 ctx->incoming = ce; |
181 pe->next = NULL; | 175 le->next = NULL; |
182 | 176 |
183 rc = next_filter(r, &ctx->out); | 177 rc = next_filter(r, &ctx->out); |
184 | |
185 if (rc == NGX_ERROR || rc == NGX_AGAIN) { | 178 if (rc == NGX_ERROR || rc == NGX_AGAIN) { |
186 return rc; | 179 return rc; |
187 } | 180 } |
188 | 181 |
189 /* NGX_OK */ | 182 /* NGX_OK */ |
195 /* copy the first hunk or its part from the chain ctx->incoming | 188 /* copy the first hunk or its part from the chain ctx->incoming |
196 to our hunk and pass it to the next filter */ | 189 to our hunk and pass it to the next filter */ |
197 do { | 190 do { |
198 rc = ngx_http_output_filter_copy_hunk(ctx->hunk, | 191 rc = ngx_http_output_filter_copy_hunk(ctx->hunk, |
199 ctx->incoming->hunk); | 192 ctx->incoming->hunk); |
200 | |
201 if (rc == NGX_ERROR) { | 193 if (rc == NGX_ERROR) { |
202 return rc; | 194 return rc; |
203 } | 195 } |
204 | 196 |
205 #if (NGX_FILE_AIO_READ) | 197 #if (NGX_FILE_AIO_READ) |
206 | |
207 if (rc == NGX_AGAIN) { | 198 if (rc == NGX_AGAIN) { |
208 return rc; | 199 return rc; |
209 } | 200 } |
210 | |
211 #endif | 201 #endif |
212 ctx->out.hunk = ctx->hunk; | 202 ctx->out.hunk = ctx->hunk; |
213 ctx->out.next = NULL; | 203 ctx->out.next = NULL; |
214 | 204 |
215 rc = next_filter(r, &ctx->out); | 205 rc = next_filter(r, &ctx->out); |
216 | |
217 if (rc == NGX_ERROR || rc == NGX_AGAIN) { | 206 if (rc == NGX_ERROR || rc == NGX_AGAIN) { |
218 return rc; | 207 return rc; |
219 } | 208 } |
220 | 209 |
221 /* NGX_OK */ | 210 /* NGX_OK */ |
222 | |
223 /* set our hunk free */ | 211 /* set our hunk free */ |
224 ctx->hunk->pos.mem = ctx->hunk->last.mem = ctx->hunk->start; | 212 ctx->hunk->pos.mem = ctx->hunk->last.mem = ctx->hunk->start; |
225 | 213 |
226 /* repeat until we will have copied the whole first hunk from | 214 /* repeat until we will have copied the whole first hunk from |
227 the chain ctx->incoming */ | 215 the chain ctx->incoming */ |
252 if (n == NGX_ERROR) { | 240 if (n == NGX_ERROR) { |
253 return n; | 241 return n; |
254 } | 242 } |
255 | 243 |
256 #if (NGX_FILE_AIO_READ) | 244 #if (NGX_FILE_AIO_READ) |
257 | |
258 if (n == NGX_AGAIN) { | 245 if (n == NGX_AGAIN) { |
259 return n; | 246 return n; |
260 } | 247 } |
261 | |
262 #endif | 248 #endif |
263 | 249 |
264 if (n != size) { | 250 if (n != size) { |
265 ngx_log_error(NGX_LOG_ALERT, src->file->log, 0, | 251 ngx_log_error(NGX_LOG_ALERT, src->file->log, 0, |
266 ngx_read_file_n " reads only %d of %d from file", | 252 ngx_read_file_n " reads only %d of %d from file", |
273 src->pos.mem += n; | 259 src->pos.mem += n; |
274 dst->last.mem += n; | 260 dst->last.mem += n; |
275 | 261 |
276 } else { | 262 } else { |
277 ngx_memcpy(src->pos.mem, dst->pos.mem, size); | 263 ngx_memcpy(src->pos.mem, dst->pos.mem, size); |
278 | |
279 src->pos.mem += size; | 264 src->pos.mem += size; |
280 dst->last.mem += size; | 265 dst->last.mem += size; |
281 } | 266 } |
282 | 267 |
283 if (src->type & NGX_HUNK_LAST && src->pos.mem == src->last.mem) { | 268 if (src->type & NGX_HUNK_LAST && src->pos.mem == src->last.mem) { |