Mercurial > hg > nginx
comparison src/event/ngx_event_proxy.c @ 151:2d9e4a8b6d11
nginx-0.0.1-2003-10-20-21:14:07 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 20 Oct 2003 17:14:07 +0000 |
parents | ad5f382c9e7d |
children | fb48bf4fea1c |
comparison
equal
deleted
inserted
replaced
150:ad5f382c9e7d | 151:2d9e4a8b6d11 |
---|---|
10 ngx_hunk_t *h); | 10 ngx_hunk_t *h); |
11 ngx_inline static void ngx_add_after_partially_filled_hunk(ngx_chain_t **chain, | 11 ngx_inline static void ngx_add_after_partially_filled_hunk(ngx_chain_t **chain, |
12 ngx_chain_t *ce); | 12 ngx_chain_t *ce); |
13 | 13 |
14 | 14 |
15 | |
16 int ngx_event_proxy(ngx_event_proxy_t *p, int do_write) | 15 int ngx_event_proxy(ngx_event_proxy_t *p, int do_write) |
17 { | 16 { |
18 for ( ;; ) { | 17 for ( ;; ) { |
19 if (do_write) { | 18 if (do_write) { |
20 if (ngx_event_proxy_write_to_downstream(p) == NGX_ABORT) { | 19 if (ngx_event_proxy_write_to_downstream(p) == NGX_ABORT) { |
103 | 102 |
104 /* use the free hunks if they exist */ | 103 /* use the free hunks if they exist */ |
105 | 104 |
106 chain = p->free_raw_hunks; | 105 chain = p->free_raw_hunks; |
107 p->free_raw_hunks = NULL; | 106 p->free_raw_hunks = NULL; |
107 ngx_log_debug(p->log, "FREE: %08X:%d" _ chain->hunk->pos _ chain->hunk->end - chain->hunk->last); | |
108 | 108 |
109 } else if (p->hunks < p->bufs.num) { | 109 } else if (p->hunks < p->bufs.num) { |
110 | 110 |
111 /* allocate a new hunk if it's still allowed */ | 111 /* allocate a new hunk if it's still allowed */ |
112 | 112 |
171 | 171 |
172 n = ngx_recv_chain(p->upstream, chain); | 172 n = ngx_recv_chain(p->upstream, chain); |
173 | 173 |
174 ngx_log_debug(p->log, "recv_chain: %d" _ n); | 174 ngx_log_debug(p->log, "recv_chain: %d" _ n); |
175 | 175 |
176 p->free_raw_hunks = chain; | |
177 | |
176 if (n == NGX_ERROR) { | 178 if (n == NGX_ERROR) { |
177 p->upstream_error = 1; | 179 p->upstream_error = 1; |
178 return NGX_ERROR; | 180 return NGX_ERROR; |
179 } | 181 } |
180 | 182 |
184 | 186 |
185 /* TODO THINK about eof */ | 187 /* TODO THINK about eof */ |
186 p->read = 1; | 188 p->read = 1; |
187 | 189 |
188 if (n == 0) { | 190 if (n == 0) { |
189 p->free_raw_hunks = chain; | |
190 p->upstream_eof = 1; | 191 p->upstream_eof = 1; |
191 | 192 break; |
192 break; | 193 } |
193 } | 194 |
194 | 195 } |
195 } | 196 |
196 | 197 ce = chain; |
197 for (ce = chain; ce && n > 0; ce = ce->next) { | 198 |
199 while (ce && n > 0) { | |
198 | 200 |
199 ngx_remove_shadow_links(ce->hunk); | 201 ngx_remove_shadow_links(ce->hunk); |
200 | 202 |
201 size = ce->hunk->end - ce->hunk->last; | 203 size = ce->hunk->end - ce->hunk->last; |
202 | 204 |
206 if (p->input_filter(p, ce->hunk) == NGX_ERROR) { | 208 if (p->input_filter(p, ce->hunk) == NGX_ERROR) { |
207 return NGX_ABORT; | 209 return NGX_ABORT; |
208 } | 210 } |
209 | 211 |
210 n -= size; | 212 n -= size; |
211 | 213 ce = ce->next; |
212 chain = ce->next; | |
213 | 214 |
214 } else { | 215 } else { |
216 ngx_log_debug(p->log, "PART: %08X:%d:%d" _ ce->hunk->pos _ ce->hunk->last - ce->hunk->pos _ n); | |
215 ce->hunk->last += n; | 217 ce->hunk->last += n; |
218 ngx_log_debug(p->log, "PART: %08X:%d" _ ce->hunk->pos _ ce->hunk->end - ce->hunk->last); | |
216 n = 0; | 219 n = 0; |
217 } | 220 } |
218 } | 221 } |
219 | 222 |
220 p->free_raw_hunks = chain; | 223 p->free_raw_hunks = ce; |
221 } | 224 } |
222 | 225 |
223 if ((p->upstream_eof || p->upstream_error) && p->free_raw_hunks) { | 226 if ((p->upstream_eof || p->upstream_error) && p->free_raw_hunks) { |
224 if (p->input_filter(p, p->free_raw_hunks->hunk) == NGX_ERROR) { | 227 if (p->input_filter(p, p->free_raw_hunks->hunk) == NGX_ERROR) { |
225 return NGX_ABORT; | 228 return NGX_ABORT; |
288 out->next = NULL; | 291 out->next = NULL; |
289 | 292 |
290 rc = p->output_filter(p->output_ctx, out->hunk); | 293 rc = p->output_filter(p->output_ctx, out->hunk); |
291 | 294 |
292 if (rc == NGX_ERROR) { | 295 if (rc == NGX_ERROR) { |
293 /* TODO */ | 296 p->downstream_error = 1; |
297 return NGX_ERROR; | |
294 } | 298 } |
295 | 299 |
296 ngx_chain_update_chains(&p->free, &p->busy, &out); | 300 ngx_chain_update_chains(&p->free, &p->busy, &out); |
297 | 301 |
298 /* calculate p->busy_len */ | 302 /* calculate p->busy_len */ |
303 } | 307 } |
304 | 308 |
305 /* add the free shadow raw hunks to p->free_raw_hunks */ | 309 /* add the free shadow raw hunks to p->free_raw_hunks */ |
306 | 310 |
307 for (ce = p->free; ce; ce = ce->next) { | 311 for (ce = p->free; ce; ce = ce->next) { |
312 ngx_log_debug(p->log, "SHADOW %08X" _ ce->hunk->shadow); | |
308 if (ce->hunk->type & NGX_HUNK_LAST_SHADOW) { | 313 if (ce->hunk->type & NGX_HUNK_LAST_SHADOW) { |
309 h = ce->hunk->shadow; | 314 h = ce->hunk->shadow; |
310 /* THINK NEEDED ??? */ h->pos = h->last = h->start; | 315 /* THINK NEEDED ??? */ h->pos = h->last = h->start; |
311 h->shadow = NULL; | 316 h->shadow = NULL; |
312 ngx_alloc_ce_and_set_hunk(te, ce->hunk->shadow, p->pool, | 317 ngx_alloc_ce_and_set_hunk(te, h, p->pool, NGX_ABORT); |
313 NGX_ABORT); | |
314 ngx_add_after_partially_filled_hunk(&p->free_raw_hunks, te); | 318 ngx_add_after_partially_filled_hunk(&p->free_raw_hunks, te); |
319 | |
320 ngx_log_debug(p->log, "RAW %08X" _ h->pos); | |
315 | 321 |
316 ce->hunk->type &= ~NGX_HUNK_LAST_SHADOW; | 322 ce->hunk->type &= ~NGX_HUNK_LAST_SHADOW; |
317 } | 323 } |
318 ce->hunk->shadow = NULL; | 324 ce->hunk->shadow = NULL; |
319 } | 325 } |
324 } | 330 } |
325 #endif | 331 #endif |
326 | 332 |
327 } | 333 } |
328 | 334 |
329 if (p->upstream_done && p->in == NULL && p->out == NULL) { | 335 ngx_log_debug(p->log, "STATE %d:%d:%d:%X:%X" _ |
336 p->upstream_eof _ | |
337 p->upstream_error _ | |
338 p->upstream_done _ | |
339 p->in _ | |
340 p->out | |
341 ); | |
342 | |
343 if ((p->upstream_eof || p->upstream_error || p->upstream_done) | |
344 && p->in == NULL && p->out == NULL) | |
345 { | |
330 p->downstream_done = 1; | 346 p->downstream_done = 1; |
331 } | 347 } |
332 | 348 |
333 return NGX_OK; | 349 return NGX_OK; |
334 } | 350 } |
363 | 379 |
364 size = 0; | 380 size = 0; |
365 ce = p->in; | 381 ce = p->in; |
366 | 382 |
367 do { | 383 do { |
384 if (size + ce->hunk->last - ce->hunk->pos | |
385 >= p->temp_file_write_size) | |
386 { | |
387 break; | |
388 } | |
368 size += ce->hunk->last - ce->hunk->pos; | 389 size += ce->hunk->last - ce->hunk->pos; |
369 if (size >= p->temp_file_write_size) { | |
370 break; | |
371 } | |
372 ce = ce->next; | 390 ce = ce->next; |
373 | 391 |
374 } while (ce); | 392 } while (ce); |
375 | 393 |
376 in = ce->next; | 394 if (ce) { |
377 last = &ce->next; | 395 in = ce->next; |
378 ce->next = NULL; | 396 last = &ce->next; |
397 ce->next = NULL; | |
398 | |
399 } else { | |
400 in = NULL; | |
401 last = &p->in; | |
402 } | |
379 | 403 |
380 } else { | 404 } else { |
381 in = NULL; | 405 in = NULL; |
382 last = &p->in; | 406 last = &p->in; |
383 } | 407 } |