Mercurial > hg > nginx
comparison src/event/ngx_event_pipe.c @ 170:c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 02 Nov 2003 22:56:18 +0000 |
parents | ba5dbb949603 |
children | caa57ddf6d77 |
comparison
equal
deleted
inserted
replaced
169:edf29bb717da | 170:c42be4185301 |
---|---|
40 } | 40 } |
41 | 41 |
42 do_write = 1; | 42 do_write = 1; |
43 } | 43 } |
44 | 44 |
45 rev = p->upstream->read; | 45 if (p->upstream->fd != -1) { |
46 | 46 rev = p->upstream->read; |
47 if (ngx_handle_read_event(rev, (rev->eof || rev->error)) == NGX_ERROR) { | 47 |
48 return NGX_ABORT; | 48 if (ngx_handle_read_event(rev, (rev->eof || rev->error)) == NGX_ERROR) { |
49 } | 49 return NGX_ABORT; |
50 | 50 } |
51 if (rev->active) { | 51 |
52 ngx_add_timer(rev, p->read_timeout); | 52 if (rev->active) { |
53 } | 53 ngx_add_timer(rev, p->read_timeout); |
54 | 54 } |
55 wev = p->downstream->write; | 55 } |
56 | 56 |
57 if (ngx_handle_write_event(wev, p->send_lowat) == NGX_ERROR) { | 57 if (p->downstream->fd != -1) { |
58 return NGX_ABORT; | 58 wev = p->downstream->write; |
59 } | 59 |
60 | 60 if (ngx_handle_write_event(wev, p->send_lowat) == NGX_ERROR) { |
61 if (wev->active) { | 61 return NGX_ABORT; |
62 ngx_add_timer(wev, p->send_timeout); | 62 } |
63 | |
64 if (wev->active) { | |
65 ngx_add_timer(wev, p->send_timeout); | |
66 } | |
63 } | 67 } |
64 | 68 |
65 return NGX_OK; | 69 return NGX_OK; |
66 } | 70 } |
67 | 71 |
164 | 168 |
165 ngx_log_debug(p->log, "downstream ready"); | 169 ngx_log_debug(p->log, "downstream ready"); |
166 | 170 |
167 break; | 171 break; |
168 | 172 |
169 } else if (p->cachable || p->temp_offset < p->max_temp_file_size) { | 173 } else if (p->cachable |
174 || p->temp_file->offset < p->max_temp_file_size) | |
175 { | |
170 | 176 |
171 /* | 177 /* |
172 * if it's allowed then save some hunks from r->in | 178 * if it's allowed then save some hunks from r->in |
173 * to a temporary file, and add them to a r->out chain | 179 * to a temporary file, and add them to a r->out chain |
174 */ | 180 */ |
175 | 181 |
176 rc = ngx_event_pipe_write_chain_to_temp_file(p); | 182 rc = ngx_event_pipe_write_chain_to_temp_file(p); |
177 | 183 |
178 ngx_log_debug(p->log, "temp offset: %d" _ p->temp_offset); | 184 ngx_log_debug(p->log, "temp offset: %d" _ p->temp_file->offset); |
179 | 185 |
180 if (rc == NGX_AGAIN) { | 186 if (rc == NGX_AGAIN) { |
181 if (ngx_event_flags & NGX_USE_LEVEL_EVENT | 187 if (ngx_event_flags & NGX_USE_LEVEL_EVENT |
182 && p->upstream->read->active | 188 && p->upstream->read->active |
183 && p->upstream->read->ready) | 189 && p->upstream->read->ready) |
412 | 418 |
413 if (p->cyclic_temp_file && (cl->hunk->type & NGX_HUNK_TEMP_FILE)) { | 419 if (p->cyclic_temp_file && (cl->hunk->type & NGX_HUNK_TEMP_FILE)) { |
414 | 420 |
415 /* reset p->temp_offset if all hunks had been sent */ | 421 /* reset p->temp_offset if all hunks had been sent */ |
416 | 422 |
417 if (cl->hunk->file_last == p->temp_offset) { | 423 if (cl->hunk->file_last == p->temp_file->offset) { |
418 p->temp_offset = 0; | 424 p->temp_file->offset = 0; |
419 } | 425 } |
420 } | 426 } |
421 } | 427 } |
422 } | 428 } |
423 | 429 |
426 | 432 |
427 | 433 |
428 static int ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p) | 434 static int ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p) |
429 { | 435 { |
430 int rc, size, hsize; | 436 int rc, size, hsize; |
437 char *save_pos; | |
431 ngx_hunk_t *h; | 438 ngx_hunk_t *h; |
432 ngx_chain_t *cl, *tl, *next, *out, **ll, **last_free; | 439 ngx_chain_t *cl, *tl, *next, *out, **ll, **last_free; |
433 | 440 |
434 ngx_log_debug(p->log, "write to file"); | 441 ngx_log_debug(p->log, "write to file"); |
435 | 442 |
436 if (p->temp_file->fd == NGX_INVALID_FILE) { | |
437 rc = ngx_create_temp_file(p->temp_file, p->temp_path, p->pool, | |
438 p->cachable); | |
439 | |
440 if (rc == NGX_ERROR) { | |
441 return NGX_ABORT; | |
442 } | |
443 | |
444 if (rc == NGX_AGAIN) { | |
445 return NGX_AGAIN; | |
446 } | |
447 | |
448 if (!p->cachable && p->temp_file_warn) { | |
449 ngx_log_error(NGX_LOG_WARN, p->log, 0, p->temp_file_warn); | |
450 } | |
451 } | |
452 | |
453 out = p->in; | 443 out = p->in; |
444 | |
445 if (out->hunk->type & NGX_HUNK_PREREAD) { | |
446 save_pos = out->hunk->pos; | |
447 out->hunk->pos = out->hunk->start; | |
448 | |
449 } else { | |
450 save_pos = NULL; | |
451 } | |
454 | 452 |
455 if (!p->cachable) { | 453 if (!p->cachable) { |
456 | 454 |
457 size = 0; | 455 size = 0; |
458 cl = p->in; | 456 cl = p->in; |
459 ll = NULL; | 457 ll = NULL; |
460 | 458 |
461 ngx_log_debug(p->log, "offset: %d" _ p->temp_offset); | 459 ngx_log_debug(p->log, "offset: %d" _ p->temp_file->offset); |
462 | 460 |
463 do { | 461 do { |
464 hsize = cl->hunk->last - cl->hunk->pos; | 462 hsize = cl->hunk->last - cl->hunk->pos; |
465 | 463 |
466 ngx_log_debug(p->log, "hunk size: %d" _ hsize); | 464 ngx_log_debug(p->log, "hunk size: %d" _ hsize); |
467 | 465 |
468 if ((size + hsize > p->temp_file_write_size) | 466 if ((size + hsize > p->temp_file_write_size) |
469 || (p->temp_offset + size + hsize > p->max_temp_file_size)) | 467 || (p->temp_file->offset + size + hsize > p->max_temp_file_size)) |
470 { | 468 { |
471 break; | 469 break; |
472 } | 470 } |
473 | 471 |
474 size += hsize; | 472 size += hsize; |
491 } else { | 489 } else { |
492 p->in = NULL; | 490 p->in = NULL; |
493 p->last_in = &p->in; | 491 p->last_in = &p->in; |
494 } | 492 } |
495 | 493 |
496 if (ngx_write_chain_to_file(p->temp_file, out, p->temp_offset, | 494 if (ngx_write_chain_to_temp_file(p->temp_file, out) == NGX_ERROR) { |
497 p->pool) == NGX_ERROR) { | |
498 return NGX_ABORT; | 495 return NGX_ABORT; |
499 } | 496 } |
500 | 497 |
501 for (last_free = &p->free_raw_hunks; | 498 for (last_free = &p->free_raw_hunks; |
502 *last_free != NULL; | 499 *last_free != NULL; |
503 last_free = &(*last_free)->next) | 500 last_free = &(*last_free)->next) |
504 { | 501 { |
505 /* void */ | 502 /* void */ |
506 } | 503 } |
507 | 504 |
505 if (out->hunk->type & NGX_HUNK_PREREAD) { | |
506 p->temp_file->offset += save_pos - out->hunk->pos; | |
507 out->hunk->pos = save_pos; | |
508 out->hunk->type &= ~NGX_HUNK_PREREAD; | |
509 } | |
510 | |
508 for (cl = out; cl; cl = next) { | 511 for (cl = out; cl; cl = next) { |
509 next = cl->next; | 512 next = cl->next; |
510 cl->next = NULL; | 513 cl->next = NULL; |
511 | 514 |
512 h = cl->hunk; | 515 h = cl->hunk; |
513 h->file = p->temp_file; | 516 h->file = &p->temp_file->file; |
514 h->file_pos = p->temp_offset; | 517 h->file_pos = p->temp_file->offset; |
515 p->temp_offset += h->last - h->pos; | 518 p->temp_file->offset += h->last - h->pos; |
516 h->file_last = p->temp_offset; | 519 h->file_last = p->temp_file->offset; |
517 | 520 |
518 if (p->cachable) { | 521 if (p->cachable) { |
519 h->type |= NGX_HUNK_FILE; | 522 h->type |= NGX_HUNK_FILE; |
520 } else { | 523 } else { |
521 h->type |= NGX_HUNK_FILE|NGX_HUNK_TEMP_FILE; | 524 h->type |= NGX_HUNK_FILE|NGX_HUNK_TEMP_FILE; |