Mercurial > hg > nginx-quic
comparison src/http/modules/proxy/ngx_http_proxy_upstream.c @ 313:98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 13 Apr 2004 15:08:48 +0000 |
parents | bcbe876f4262 |
children | d71c87d11b16 |
comparison
equal
deleted
inserted
replaced
312:f5431a4bbc7d | 313:98f1a8028067 |
---|---|
325 ngx_del_timer(r->connection->read); | 325 ngx_del_timer(r->connection->read); |
326 } | 326 } |
327 | 327 |
328 r->connection->read->event_handler = ngx_http_proxy_check_broken_connection; | 328 r->connection->read->event_handler = ngx_http_proxy_check_broken_connection; |
329 | 329 |
330 if ((ngx_event_flags & (NGX_USE_CLEAR_EVENT|NGX_HAVE_KQUEUE_EVENT)) | 330 if (ngx_event_flags & (NGX_USE_CLEAR_EVENT|NGX_HAVE_KQUEUE_EVENT)) { |
331 && !r->connection->write->active) | 331 |
332 { | |
333 /* kqueue allows to detect when client closes prematurely connection */ | 332 /* kqueue allows to detect when client closes prematurely connection */ |
334 | 333 |
335 r->connection->write->event_handler = | 334 r->connection->write->event_handler = |
336 ngx_http_proxy_check_broken_connection; | 335 ngx_http_proxy_check_broken_connection; |
337 | 336 |
338 if (ngx_add_event(r->connection->write, NGX_WRITE_EVENT, | 337 if (!r->connection->write->active) { |
338 if (ngx_add_event(r->connection->write, NGX_WRITE_EVENT, | |
339 NGX_CLEAR_EVENT) == NGX_ERROR) | 339 NGX_CLEAR_EVENT) == NGX_ERROR) |
340 { | 340 { |
341 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 341 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
342 return; | 342 return; |
343 } | |
343 } | 344 } |
344 } | 345 } |
345 | 346 |
346 | 347 |
347 if (!(cl = ngx_http_proxy_create_request(p))) { | 348 if (!(cl = ngx_http_proxy_create_request(p))) { |
558 | 559 |
559 p->action = "connecting to upstream"; | 560 p->action = "connecting to upstream"; |
560 | 561 |
561 rc = ngx_event_connect_peer(&p->upstream->peer); | 562 rc = ngx_event_connect_peer(&p->upstream->peer); |
562 | 563 |
564 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, | |
565 "http proxy connect: %d", rc); | |
566 | |
563 if (rc == NGX_ERROR) { | 567 if (rc == NGX_ERROR) { |
564 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); | 568 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); |
565 return; | 569 return; |
566 } | 570 } |
567 | 571 |
571 if (rc == NGX_CONNECT_ERROR) { | 575 if (rc == NGX_CONNECT_ERROR) { |
572 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_ERROR); | 576 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_ERROR); |
573 return; | 577 return; |
574 } | 578 } |
575 | 579 |
576 p->upstream->peer.connection->data = p; | |
577 p->upstream->peer.connection->write->event_handler = | |
578 ngx_http_proxy_send_request_handler; | |
579 p->upstream->peer.connection->read->event_handler = | |
580 ngx_http_proxy_process_upstream_status_line; | |
581 | |
582 r = p->request; | 580 r = p->request; |
583 c = p->upstream->peer.connection; | 581 c = p->upstream->peer.connection; |
582 | |
583 c->data = p; | |
584 c->write->event_handler = ngx_http_proxy_send_request_handler; | |
585 c->read->event_handler = ngx_http_proxy_process_upstream_status_line; | |
586 | |
584 c->pool = r->pool; | 587 c->pool = r->pool; |
585 c->read->log = c->write->log = c->log = r->connection->log; | 588 c->read->log = c->write->log = c->log = r->connection->log; |
586 | 589 |
587 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ | 590 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ |
588 | 591 |
611 | 614 |
612 p->request_sent = 0; | 615 p->request_sent = 0; |
613 | 616 |
614 if (rc == NGX_AGAIN) { | 617 if (rc == NGX_AGAIN) { |
615 ngx_add_timer(c->write, p->lcf->connect_timeout); | 618 ngx_add_timer(c->write, p->lcf->connect_timeout); |
619 | |
620 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
621 "http proxy connect handler: " PTR_FMT, | |
622 c->write->event_handler); | |
623 | |
616 return; | 624 return; |
617 } | 625 } |
618 | 626 |
619 /* rc == NGX_OK */ | 627 /* rc == NGX_OK */ |
620 | 628 |
635 { | 643 { |
636 int rc; | 644 int rc; |
637 ngx_connection_t *c; | 645 ngx_connection_t *c; |
638 | 646 |
639 c = p->upstream->peer.connection; | 647 c = p->upstream->peer.connection; |
648 | |
649 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
650 "http proxy send request"); | |
640 | 651 |
641 #if (HAVE_KQUEUE) | 652 #if (HAVE_KQUEUE) |
642 | 653 |
643 if ((ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) | 654 if ((ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) |
644 && !p->request_sent | 655 && !p->request_sent |
713 ngx_http_proxy_process_upstream_status_line(c->read); | 724 ngx_http_proxy_process_upstream_status_line(c->read); |
714 return; | 725 return; |
715 } | 726 } |
716 #endif | 727 #endif |
717 | 728 |
718 p->upstream->peer.connection->write->event_handler = | 729 c->write->event_handler = ngx_http_proxy_dummy_handler; |
719 ngx_http_proxy_dummy_handler; | |
720 | 730 |
721 if (ngx_handle_level_write_event(c->write) == NGX_ERROR) { | 731 if (ngx_handle_level_write_event(c->write) == NGX_ERROR) { |
722 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); | 732 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); |
723 return; | 733 return; |
724 } | 734 } |
730 ngx_connection_t *c; | 740 ngx_connection_t *c; |
731 ngx_http_proxy_ctx_t *p; | 741 ngx_http_proxy_ctx_t *p; |
732 | 742 |
733 c = wev->data; | 743 c = wev->data; |
734 p = c->data; | 744 p = c->data; |
745 | |
746 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, | |
747 "http proxy send request handler"); | |
735 | 748 |
736 if (wev->timedout) { | 749 if (wev->timedout) { |
737 p->action = "sending request to upstream"; | 750 p->action = "sending request to upstream"; |
738 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_TIMEOUT); | 751 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_TIMEOUT); |
739 return; | 752 return; |