Mercurial > hg > nginx
comparison src/http/ngx_http_request.c @ 5114:a46c1cfe7263
Allow to reuse connections that wait their first request.
This should improve behavior under deficiency of connections.
Since SSL handshake usually takes significant amount of time,
we exclude connections from reusable queue during this period
to avoid premature flush of them.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Fri, 15 Mar 2013 19:49:54 +0000 |
parents | 44bd04fbbb4f |
children | f10108c92fef |
comparison
equal
deleted
inserted
replaced
5113:08b36f2afc3f | 5114:a46c1cfe7263 |
---|---|
353 rev->handler(rev); | 353 rev->handler(rev); |
354 return; | 354 return; |
355 } | 355 } |
356 | 356 |
357 ngx_add_timer(rev, c->listening->post_accept_timeout); | 357 ngx_add_timer(rev, c->listening->post_accept_timeout); |
358 ngx_reusable_connection(c, 1); | |
358 | 359 |
359 if (ngx_handle_read_event(rev, 0) != NGX_OK) { | 360 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
360 ngx_http_close_connection(c); | 361 ngx_http_close_connection(c); |
361 return; | 362 return; |
362 } | 363 } |
377 | 378 |
378 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http wait request handler"); | 379 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http wait request handler"); |
379 | 380 |
380 if (rev->timedout) { | 381 if (rev->timedout) { |
381 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | 382 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); |
383 ngx_http_close_connection(c); | |
384 return; | |
385 } | |
386 | |
387 if (c->close) { | |
382 ngx_http_close_connection(c); | 388 ngx_http_close_connection(c); |
383 return; | 389 return; |
384 } | 390 } |
385 | 391 |
386 hc = c->data; | 392 hc = c->data; |
430 } | 436 } |
431 #endif | 437 #endif |
432 | 438 |
433 if (!rev->timer_set) { | 439 if (!rev->timer_set) { |
434 ngx_add_timer(rev, c->listening->post_accept_timeout); | 440 ngx_add_timer(rev, c->listening->post_accept_timeout); |
441 ngx_reusable_connection(c, 1); | |
435 } | 442 } |
436 | 443 |
437 if (ngx_handle_read_event(rev, 0) != NGX_OK) { | 444 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
438 ngx_http_close_connection(c); | 445 ngx_http_close_connection(c); |
439 return; | 446 return; |
463 } | 470 } |
464 | 471 |
465 b->last += n; | 472 b->last += n; |
466 | 473 |
467 c->log->action = "reading client request line"; | 474 c->log->action = "reading client request line"; |
475 | |
476 ngx_reusable_connection(c, 0); | |
468 | 477 |
469 c->data = ngx_http_create_request(c); | 478 c->data = ngx_http_create_request(c); |
470 if (c->data == NULL) { | 479 if (c->data == NULL) { |
471 ngx_http_close_connection(c); | 480 ngx_http_close_connection(c); |
472 return; | 481 return; |
609 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | 618 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); |
610 ngx_http_close_connection(c); | 619 ngx_http_close_connection(c); |
611 return; | 620 return; |
612 } | 621 } |
613 | 622 |
623 if (c->close) { | |
624 ngx_http_close_connection(c); | |
625 return; | |
626 } | |
627 | |
614 n = recv(c->fd, (char *) buf, 1, MSG_PEEK); | 628 n = recv(c->fd, (char *) buf, 1, MSG_PEEK); |
615 | 629 |
616 err = ngx_socket_errno; | 630 err = ngx_socket_errno; |
617 | 631 |
618 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http recv(): %d", n); | 632 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http recv(): %d", n); |
629 } | 643 } |
630 #endif | 644 #endif |
631 | 645 |
632 if (!rev->timer_set) { | 646 if (!rev->timer_set) { |
633 ngx_add_timer(rev, c->listening->post_accept_timeout); | 647 ngx_add_timer(rev, c->listening->post_accept_timeout); |
648 ngx_reusable_connection(c, 1); | |
634 } | 649 } |
635 | 650 |
636 if (ngx_handle_read_event(rev, 0) != NGX_OK) { | 651 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
637 ngx_http_close_connection(c); | 652 ngx_http_close_connection(c); |
638 } | 653 } |
667 if (rc == NGX_AGAIN) { | 682 if (rc == NGX_AGAIN) { |
668 | 683 |
669 if (!rev->timer_set) { | 684 if (!rev->timer_set) { |
670 ngx_add_timer(rev, c->listening->post_accept_timeout); | 685 ngx_add_timer(rev, c->listening->post_accept_timeout); |
671 } | 686 } |
687 | |
688 ngx_reusable_connection(c, 0); | |
672 | 689 |
673 c->ssl->handler = ngx_http_ssl_handshake_handler; | 690 c->ssl->handler = ngx_http_ssl_handshake_handler; |
674 return; | 691 return; |
675 } | 692 } |
676 | 693 |
711 | 728 |
712 c->log->action = "waiting for request"; | 729 c->log->action = "waiting for request"; |
713 | 730 |
714 c->read->handler = ngx_http_wait_request_handler; | 731 c->read->handler = ngx_http_wait_request_handler; |
715 /* STUB: epoll edge */ c->write->handler = ngx_http_empty_handler; | 732 /* STUB: epoll edge */ c->write->handler = ngx_http_empty_handler; |
733 | |
734 ngx_reusable_connection(c, 1); | |
716 | 735 |
717 ngx_http_wait_request_handler(c->read); | 736 ngx_http_wait_request_handler(c->read); |
718 | 737 |
719 return; | 738 return; |
720 } | 739 } |