Mercurial > hg > nginx
comparison src/event/ngx_event_pipe.c @ 304:bcbe876f4262
nginx-0.0.3-2004-04-02-09:14:40 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 02 Apr 2004 05:14:40 +0000 |
parents | 5cfd65b8b0a7 |
children | 6bdf858bff8c |
comparison
equal
deleted
inserted
replaced
303:00c5660d2707 | 304:bcbe876f4262 |
---|---|
98 | 98 |
99 if (p->preread_hunks) { | 99 if (p->preread_hunks) { |
100 | 100 |
101 /* use the pre-read hunks if they exist */ | 101 /* use the pre-read hunks if they exist */ |
102 | 102 |
103 p->read = 1; | |
104 chain = p->preread_hunks; | 103 chain = p->preread_hunks; |
105 p->preread_hunks = NULL; | 104 p->preread_hunks = NULL; |
106 n = p->preread_size; | 105 n = p->preread_size; |
107 | 106 |
108 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, | 107 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, |
109 "pipe preread: %d", n); | 108 "pipe preread: %d", n); |
109 | |
110 if (n) { | |
111 p->read = 1; | |
112 } | |
110 | 113 |
111 } else { | 114 } else { |
112 | 115 |
113 /* | 116 /* |
114 * kqueue notifies about the end of file or a pending error. | 117 * kqueue notifies about the end of file or a pending error. |
284 } | 287 } |
285 | 288 |
286 p->free_raw_hunks = cl; | 289 p->free_raw_hunks = cl; |
287 } | 290 } |
288 | 291 |
292 #if (NGX_DEBUG0) | |
293 | |
294 if (p->in || p->busy || p->free_raw_hunks) { | |
295 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0, "pipe buf"); | |
296 } | |
297 | |
298 for (cl = p->in; cl; cl = cl->next) { | |
299 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, | |
300 "pipe buf in " PTR_FMT ", pos " PTR_FMT ", size: %d", | |
301 cl->hunk->start, cl->hunk->pos, | |
302 cl->hunk->last - cl->hunk->pos); | |
303 } | |
304 | |
305 for (cl = p->busy; cl; cl = cl->next) { | |
306 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, | |
307 "pipe buf busy " PTR_FMT ", pos " PTR_FMT ", size: %d", | |
308 cl->hunk->start, cl->hunk->pos, | |
309 cl->hunk->last - cl->hunk->pos); | |
310 } | |
311 | |
312 for (cl = p->free_raw_hunks; cl; cl = cl->next) { | |
313 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, | |
314 "pipe buf free " PTR_FMT ", last " PTR_FMT ", size: %d", | |
315 cl->hunk->start, cl->hunk->last, | |
316 cl->hunk->end - cl->hunk->last); | |
317 } | |
318 | |
319 #endif | |
320 | |
289 if ((p->upstream_eof || p->upstream_error) && p->free_raw_hunks) { | 321 if ((p->upstream_eof || p->upstream_error) && p->free_raw_hunks) { |
290 | 322 |
291 /* STUB */ p->free_raw_hunks->hunk->num = p->num++; | 323 /* STUB */ p->free_raw_hunks->hunk->num = p->num++; |
292 | 324 |
293 if (p->input_filter(p, p->free_raw_hunks->hunk) == NGX_ERROR) { | 325 if (p->input_filter(p, p->free_raw_hunks->hunk) == NGX_ERROR) { |
313 } | 345 } |
314 | 346 |
315 | 347 |
316 int ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) | 348 int ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) |
317 { | 349 { |
318 size_t bsize, to_write; | 350 size_t bsize; |
351 ngx_uint_t flush; | |
319 ngx_hunk_t *h; | 352 ngx_hunk_t *h; |
320 ngx_chain_t *out, **ll, *cl, *tl; | 353 ngx_chain_t *out, **ll, *cl, *tl; |
321 | 354 |
322 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, | 355 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, |
323 "pipe write downstream: %d", p->downstream->write->ready); | 356 "pipe write downstream: %d", p->downstream->write->ready); |
366 | 399 |
367 if (!p->downstream->write->ready) { | 400 if (!p->downstream->write->ready) { |
368 break; | 401 break; |
369 } | 402 } |
370 | 403 |
371 /* | 404 /* bsize is the size of the busy hunks */ |
372 * bsize is the size of the busy hunks, | |
373 * to_write is the size of data in these hunks that | |
374 * would be written to a socket | |
375 */ | |
376 | 405 |
377 bsize = 0; | 406 bsize = 0; |
378 to_write = 0; | 407 |
379 | 408 for (cl = p->busy; cl; cl = cl->next) { |
380 #if 0 | 409 bsize += cl->hunk->end - cl->hunk->start; |
381 if (!(p->upstream_eof || p->upstream_error || p->upstream_done)) { | 410 } |
382 #endif | 411 |
383 for (cl = p->busy; cl; cl = cl->next) { | 412 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, |
384 bsize += cl->hunk->end - cl->hunk->start; | 413 "pipe write busy: " SIZE_T_FMT, bsize); |
385 to_write += ngx_hunk_size(cl->hunk); | |
386 } | |
387 #if 0 | |
388 } | |
389 #endif | |
390 | 414 |
391 out = NULL; | 415 out = NULL; |
392 ll = NULL; | 416 ll = NULL; |
417 flush = 0; | |
393 | 418 |
394 for ( ;; ) { | 419 for ( ;; ) { |
395 if (p->out) { | 420 if (p->out) { |
396 cl = p->out; | 421 cl = p->out; |
397 | 422 |
398 #if 0 | 423 if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) { |
399 if (!(p->upstream_eof || p->upstream_error || p->upstream_done) | 424 flush = 1; |
400 && (bsize + ngx_hunk_size(cl->hunk) > p->busy_size)) | |
401 { | |
402 break; | 425 break; |
403 } | 426 } |
404 #else | |
405 if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) { | |
406 break; | |
407 } | |
408 #endif | |
409 | 427 |
410 p->out = p->out->next; | 428 p->out = p->out->next; |
411 ngx_event_pipe_free_shadow_raw_hunk(&p->free_raw_hunks, | 429 ngx_event_pipe_free_shadow_raw_hunk(&p->free_raw_hunks, |
412 cl->hunk); | 430 cl->hunk); |
413 | 431 |
414 } else if (!p->cachable && p->in) { | 432 } else if (!p->cachable && p->in) { |
415 cl = p->in; | 433 cl = p->in; |
416 | 434 |
417 #if 0 | 435 if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) { |
418 if (!(p->upstream_eof || p->upstream_error || p->upstream_done) | 436 flush = 1; |
419 && (bsize + ngx_hunk_size(cl->hunk) > p->busy_size)) | |
420 { | |
421 break; | 437 break; |
422 } | 438 } |
423 #else | |
424 if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) { | |
425 break; | |
426 } | |
427 #endif | |
428 | 439 |
429 p->in = p->in->next; | 440 p->in = p->in->next; |
430 | 441 |
431 } else { | 442 } else { |
432 break; | 443 break; |
435 bsize += ngx_hunk_size(cl->hunk); | 446 bsize += ngx_hunk_size(cl->hunk); |
436 cl->next = NULL; | 447 cl->next = NULL; |
437 ngx_chain_add_link(out, ll, cl); | 448 ngx_chain_add_link(out, ll, cl); |
438 } | 449 } |
439 | 450 |
440 if (out == NULL) { | 451 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0, |
441 | 452 "pipe write: out:" PTR_FMT ", f:%d", out, flush); |
442 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, | 453 |
443 "pipe busy hunk data to write: %d", to_write); | 454 if (out == NULL && !flush) { |
444 | 455 break; |
445 if (!(p->upstream_blocked && to_write)) { | 456 } |
446 break; | |
447 } | |
448 | |
449 } | |
450 | |
451 /* | |
452 * if the upstream is blocked and there are the busy hunks | |
453 * to write then write these hunks | |
454 */ | |
455 | 457 |
456 if (p->output_filter(p->output_ctx, out) == NGX_ERROR) { | 458 if (p->output_filter(p->output_ctx, out) == NGX_ERROR) { |
457 p->downstream_error = 1; | 459 p->downstream_error = 1; |
458 return ngx_event_pipe_drain_chains(p); | 460 return ngx_event_pipe_drain_chains(p); |
459 } | 461 } |
531 "pipe offset: %d", p->temp_file->offset); | 533 "pipe offset: %d", p->temp_file->offset); |
532 | 534 |
533 do { | 535 do { |
534 hsize = cl->hunk->last - cl->hunk->pos; | 536 hsize = cl->hunk->last - cl->hunk->pos; |
535 | 537 |
536 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, | 538 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, |
537 "pipe hunk size: %d", hsize); | 539 "pipe buf " PTR_FMT ", pos " PTR_FMT ", size: %d", |
540 cl->hunk->start, cl->hunk->pos, hsize); | |
538 | 541 |
539 if ((size + hsize > p->temp_file_write_size) | 542 if ((size + hsize > p->temp_file_write_size) |
540 || (p->temp_file->offset + size + hsize > p->max_temp_file_size)) | 543 || (p->temp_file->offset + size + hsize > p->max_temp_file_size)) |
541 { | 544 { |
542 break; | 545 break; |