comparison src/http/ngx_http_upstream.c @ 3052:6060225e9261

FreeBSD and Linux AIO support
author Igor Sysoev <igor@sysoev.ru>
date Fri, 28 Aug 2009 08:12:35 +0000
parents f54b02dbb12b
children 0d253659da12
comparison
equal deleted inserted replaced
3051:26dfc0fa22c8 3052:6060225e9261
16 ngx_http_upstream_t *u); 16 ngx_http_upstream_t *u);
17 static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r, 17 static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r,
18 ngx_http_variable_value_t *v, uintptr_t data); 18 ngx_http_variable_value_t *v, uintptr_t data);
19 #endif 19 #endif
20 20
21 static void ngx_http_upstream_init_request(ngx_http_request_t *r);
21 static void ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx); 22 static void ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx);
22 static void ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r); 23 static void ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r);
23 static void ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r); 24 static void ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r);
24 static void ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, 25 static void ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
25 ngx_event_t *ev); 26 ngx_event_t *ev);
384 385
385 386
386 void 387 void
387 ngx_http_upstream_init(ngx_http_request_t *r) 388 ngx_http_upstream_init(ngx_http_request_t *r)
388 { 389 {
390 ngx_connection_t *c;
391
392 c = r->connection;
393
394 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
395 "http init upstream, client timer: %d", c->read->timer_set);
396
397 if (c->read->timer_set) {
398 ngx_del_timer(c->read);
399 }
400
401 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) {
402
403 if (!c->write->active) {
404 if (ngx_add_event(c->write, NGX_WRITE_EVENT, NGX_CLEAR_EVENT)
405 == NGX_ERROR)
406 {
407 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
408 return;
409 }
410 }
411 }
412
413 ngx_http_upstream_init_request(r);
414 }
415
416
417 static void
418 ngx_http_upstream_init_request(ngx_http_request_t *r)
419 {
389 ngx_str_t *host; 420 ngx_str_t *host;
390 ngx_uint_t i; 421 ngx_uint_t i;
391 ngx_connection_t *c;
392 ngx_resolver_ctx_t *ctx, temp; 422 ngx_resolver_ctx_t *ctx, temp;
393 ngx_http_cleanup_t *cln; 423 ngx_http_cleanup_t *cln;
394 ngx_http_upstream_t *u; 424 ngx_http_upstream_t *u;
395 ngx_http_core_loc_conf_t *clcf; 425 ngx_http_core_loc_conf_t *clcf;
396 ngx_http_upstream_srv_conf_t *uscf, **uscfp; 426 ngx_http_upstream_srv_conf_t *uscf, **uscfp;
397 ngx_http_upstream_main_conf_t *umcf; 427 ngx_http_upstream_main_conf_t *umcf;
398 428
399 c = r->connection; 429 if (r->aio) {
400 430 return;
401 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
402 "http init upstream, client timer: %d", c->read->timer_set);
403
404 if (c->read->timer_set) {
405 ngx_del_timer(c->read);
406 } 431 }
407 432
408 u = r->upstream; 433 u = r->upstream;
434
435 #if (NGX_HTTP_CACHE)
436
437 if (u->conf->cache) {
438 ngx_int_t rc;
439
440 rc = ngx_http_upstream_cache(r, u);
441
442 if (rc == NGX_AGAIN) {
443 r->write_event_handler = ngx_http_upstream_init_request;
444 return;
445 }
446
447 if (rc == NGX_DONE) {
448 return;
449 }
450
451 if (rc != NGX_DECLINED) {
452 ngx_http_finalize_request(r, rc);
453 return;
454 }
455 }
456
457 #endif
409 458
410 u->store = (u->conf->store || u->conf->store_lengths); 459 u->store = (u->conf->store || u->conf->store_lengths);
411 460
412 if (!u->store && !r->post_action && !u->conf->ignore_client_abort) { 461 if (!u->store && !r->post_action && !u->conf->ignore_client_abort) {
413 r->read_event_handler = ngx_http_upstream_rd_check_broken_connection; 462 r->read_event_handler = ngx_http_upstream_rd_check_broken_connection;
414 r->write_event_handler = ngx_http_upstream_wr_check_broken_connection; 463 r->write_event_handler = ngx_http_upstream_wr_check_broken_connection;
415 } 464 }
416 465
417 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) {
418
419 if (!c->write->active) {
420 if (ngx_add_event(c->write, NGX_WRITE_EVENT, NGX_CLEAR_EVENT)
421 == NGX_ERROR)
422 {
423 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
424 return;
425 }
426 }
427 }
428
429 if (r->request_body) { 466 if (r->request_body) {
430 u->request_bufs = r->request_body->bufs; 467 u->request_bufs = r->request_body->bufs;
431 } 468 }
432
433 #if (NGX_HTTP_CACHE)
434
435 if (u->conf->cache) {
436 ngx_int_t rc;
437
438 rc = ngx_http_upstream_cache(r, u);
439
440 if (rc == NGX_DONE) {
441 return;
442 }
443
444 if (rc != NGX_DECLINED) {
445 ngx_http_finalize_request(r, rc);
446 return;
447 }
448 }
449
450 #endif
451 469
452 if (u->create_request(r) != NGX_OK) { 470 if (u->create_request(r) != NGX_OK) {
453 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 471 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
454 return; 472 return;
455 } 473 }
541 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 559 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
542 return; 560 return;
543 } 561 }
544 562
545 if (ctx == NGX_NO_RESOLVER) { 563 if (ctx == NGX_NO_RESOLVER) {
546 ngx_log_error(NGX_LOG_ERR, c->log, 0, 564 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
547 "no resolver defined to resolve %V", host); 565 "no resolver defined to resolve %V", host);
548 566
549 ngx_http_finalize_request(r, NGX_HTTP_BAD_GATEWAY); 567 ngx_http_finalize_request(r, NGX_HTTP_BAD_GATEWAY);
550 return; 568 return;
551 } 569 }
655 return rc; 673 return rc;
656 } 674 }
657 675
658 break; 676 break;
659 677
660 case NGX_ERROR:
661
662 return NGX_ERROR;
663
664 case NGX_HTTP_CACHE_STALE: 678 case NGX_HTTP_CACHE_STALE:
665 679
666 c->valid_sec = 0; 680 c->valid_sec = 0;
667 u->buffer.start = NULL; 681 u->buffer.start = NULL;
668 u->cache_status = NGX_HTTP_CACHE_EXPIRED; 682 u->cache_status = NGX_HTTP_CACHE_EXPIRED;
679 u->buffer.last = u->buffer.pos; 693 u->buffer.last = u->buffer.pos;
680 } 694 }
681 695
682 break; 696 break;
683 697
698 case NGX_HTTP_CACHE_SCARCE:
699
700 u->cacheable = 0;
701
702 break;
703
684 case NGX_AGAIN: 704 case NGX_AGAIN:
685 705
686 u->cacheable = 0; 706 return NGX_AGAIN;
687 707
688 break; 708 case NGX_ERROR:
709
710 return NGX_ERROR;
689 711
690 default: 712 default:
691 713
692 /* cached NGX_HTTP_BAD_GATEWAY, NGX_HTTP_GATEWAY_TIME_OUT, etc. */ 714 /* cached NGX_HTTP_BAD_GATEWAY, NGX_HTTP_GATEWAY_TIME_OUT, etc. */
693 715