Mercurial > hg > nginx
comparison src/http/ngx_http_upstream_round_robin.c @ 6103:79ddb0bdb273
Upstream: the "zone" directive.
Upstreams with the "zone" directive are kept in shared memory,
with a consistent view of all worker processes.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Tue, 14 Apr 2015 19:01:25 +0300 |
parents | 3264b7828f72 |
children | 4a640716f4e2 |
comparison
equal
deleted
inserted
replaced
6102:3264b7828f72 | 6103:79ddb0bdb273 |
---|---|
655 ngx_http_upstream_set_round_robin_peer_session(ngx_peer_connection_t *pc, | 655 ngx_http_upstream_set_round_robin_peer_session(ngx_peer_connection_t *pc, |
656 void *data) | 656 void *data) |
657 { | 657 { |
658 ngx_http_upstream_rr_peer_data_t *rrp = data; | 658 ngx_http_upstream_rr_peer_data_t *rrp = data; |
659 | 659 |
660 ngx_int_t rc; | 660 ngx_int_t rc; |
661 ngx_ssl_session_t *ssl_session; | 661 ngx_ssl_session_t *ssl_session; |
662 ngx_http_upstream_rr_peer_t *peer; | 662 ngx_http_upstream_rr_peer_t *peer; |
663 #if (NGX_HTTP_UPSTREAM_ZONE) | |
664 int len; | |
665 #if OPENSSL_VERSION_NUMBER >= 0x0090707fL | |
666 const | |
667 #endif | |
668 u_char *p; | |
669 ngx_http_upstream_rr_peers_t *peers; | |
670 u_char buf[NGX_SSL_MAX_SESSION_SIZE]; | |
671 #endif | |
663 | 672 |
664 peer = rrp->current; | 673 peer = rrp->current; |
674 | |
675 #if (NGX_HTTP_UPSTREAM_ZONE) | |
676 peers = rrp->peers; | |
677 | |
678 if (peers->shpool) { | |
679 ngx_http_upstream_rr_peers_rlock(peers); | |
680 ngx_http_upstream_rr_peer_lock(peers, peer); | |
681 | |
682 if (peer->ssl_session == NULL) { | |
683 ngx_http_upstream_rr_peer_unlock(peers, peer); | |
684 ngx_http_upstream_rr_peers_unlock(peers); | |
685 return NGX_OK; | |
686 } | |
687 | |
688 len = peer->ssl_session_len; | |
689 | |
690 ngx_memcpy(buf, peer->ssl_session, len); | |
691 | |
692 ngx_http_upstream_rr_peer_unlock(peers, peer); | |
693 ngx_http_upstream_rr_peers_unlock(peers); | |
694 | |
695 p = buf; | |
696 ssl_session = d2i_SSL_SESSION(NULL, &p, len); | |
697 | |
698 rc = ngx_ssl_set_session(pc->connection, ssl_session); | |
699 | |
700 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, | |
701 "set session: %p", ssl_session); | |
702 | |
703 ngx_ssl_free_session(ssl_session); | |
704 | |
705 return rc; | |
706 } | |
707 #endif | |
665 | 708 |
666 ssl_session = peer->ssl_session; | 709 ssl_session = peer->ssl_session; |
667 | 710 |
668 rc = ngx_ssl_set_session(pc->connection, ssl_session); | 711 rc = ngx_ssl_set_session(pc->connection, ssl_session); |
669 | 712 |
678 ngx_http_upstream_save_round_robin_peer_session(ngx_peer_connection_t *pc, | 721 ngx_http_upstream_save_round_robin_peer_session(ngx_peer_connection_t *pc, |
679 void *data) | 722 void *data) |
680 { | 723 { |
681 ngx_http_upstream_rr_peer_data_t *rrp = data; | 724 ngx_http_upstream_rr_peer_data_t *rrp = data; |
682 | 725 |
683 ngx_ssl_session_t *old_ssl_session, *ssl_session; | 726 ngx_ssl_session_t *old_ssl_session, *ssl_session; |
684 ngx_http_upstream_rr_peer_t *peer; | 727 ngx_http_upstream_rr_peer_t *peer; |
728 #if (NGX_HTTP_UPSTREAM_ZONE) | |
729 int len; | |
730 u_char *p; | |
731 ngx_http_upstream_rr_peers_t *peers; | |
732 u_char buf[NGX_SSL_MAX_SESSION_SIZE]; | |
733 #endif | |
734 | |
735 #if (NGX_HTTP_UPSTREAM_ZONE) | |
736 peers = rrp->peers; | |
737 | |
738 if (peers->shpool) { | |
739 | |
740 ssl_session = SSL_get0_session(pc->connection->ssl->connection); | |
741 | |
742 if (ssl_session == NULL) { | |
743 return; | |
744 } | |
745 | |
746 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, | |
747 "save session: %p", ssl_session); | |
748 | |
749 len = i2d_SSL_SESSION(ssl_session, NULL); | |
750 | |
751 /* do not cache too big session */ | |
752 | |
753 if (len > NGX_SSL_MAX_SESSION_SIZE) { | |
754 return; | |
755 } | |
756 | |
757 p = buf; | |
758 (void) i2d_SSL_SESSION(ssl_session, &p); | |
759 | |
760 peer = rrp->current; | |
761 | |
762 ngx_http_upstream_rr_peers_rlock(peers); | |
763 ngx_http_upstream_rr_peer_lock(peers, peer); | |
764 | |
765 if (len > peer->ssl_session_len) { | |
766 ngx_shmtx_lock(&peers->shpool->mutex); | |
767 | |
768 if (peer->ssl_session) { | |
769 ngx_slab_free_locked(peers->shpool, peer->ssl_session); | |
770 } | |
771 | |
772 peer->ssl_session = ngx_slab_alloc_locked(peers->shpool, len); | |
773 | |
774 ngx_shmtx_unlock(&peers->shpool->mutex); | |
775 | |
776 if (peer->ssl_session == NULL) { | |
777 peer->ssl_session_len = 0; | |
778 | |
779 ngx_http_upstream_rr_peer_unlock(peers, peer); | |
780 ngx_http_upstream_rr_peers_unlock(peers); | |
781 return; | |
782 } | |
783 | |
784 peer->ssl_session_len = len; | |
785 } | |
786 | |
787 ngx_memcpy(peer->ssl_session, buf, len); | |
788 | |
789 ngx_http_upstream_rr_peer_unlock(peers, peer); | |
790 ngx_http_upstream_rr_peers_unlock(peers); | |
791 | |
792 return; | |
793 } | |
794 #endif | |
685 | 795 |
686 ssl_session = ngx_ssl_get_session(pc->connection); | 796 ssl_session = ngx_ssl_get_session(pc->connection); |
687 | 797 |
688 if (ssl_session == NULL) { | 798 if (ssl_session == NULL) { |
689 return; | 799 return; |