Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.11 ]​[ nginx-1.14.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_HTTP_UPSTREAM_ROUND_ROBIN_H_INCLUDED_
0009 #define _NGX_HTTP_UPSTREAM_ROUND_ROBIN_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 #include <ngx_http.h>
0015 
0016 
0017 typedef struct ngx_http_upstream_rr_peer_s   ngx_http_upstream_rr_peer_t;
0018 
0019 struct ngx_http_upstream_rr_peer_s {
0020     struct sockaddr                *sockaddr;
0021     socklen_t                       socklen;
0022     ngx_str_t                       name;
0023     ngx_str_t                       server;
0024 
0025     ngx_int_t                       current_weight;
0026     ngx_int_t                       effective_weight;
0027     ngx_int_t                       weight;
0028 
0029     ngx_uint_t                      conns;
0030     ngx_uint_t                      max_conns;
0031 
0032     ngx_uint_t                      fails;
0033     time_t                          accessed;
0034     time_t                          checked;
0035 
0036     ngx_uint_t                      max_fails;
0037     time_t                          fail_timeout;
0038     ngx_msec_t                      slow_start;
0039     ngx_msec_t                      start_time;
0040 
0041     ngx_uint_t                      down;
0042 
0043 #if (NGX_HTTP_SSL || NGX_COMPAT)
0044     void                           *ssl_session;
0045     int                             ssl_session_len;
0046 #endif
0047 
0048 #if (NGX_HTTP_UPSTREAM_ZONE)
0049     ngx_atomic_t                    lock;
0050 #endif
0051 
0052     ngx_http_upstream_rr_peer_t    *next;
0053 
0054     NGX_COMPAT_BEGIN(32)
0055     NGX_COMPAT_END
0056 };
0057 
0058 
0059 typedef struct ngx_http_upstream_rr_peers_s  ngx_http_upstream_rr_peers_t;
0060 
0061 struct ngx_http_upstream_rr_peers_s {
0062     ngx_uint_t                      number;
0063 
0064 #if (NGX_HTTP_UPSTREAM_ZONE)
0065     ngx_slab_pool_t                *shpool;
0066     ngx_atomic_t                    rwlock;
0067     ngx_http_upstream_rr_peers_t   *zone_next;
0068 #endif
0069 
0070     ngx_uint_t                      total_weight;
0071 
0072     unsigned                        single:1;
0073     unsigned                        weighted:1;
0074 
0075     ngx_str_t                      *name;
0076 
0077     ngx_http_upstream_rr_peers_t   *next;
0078 
0079     ngx_http_upstream_rr_peer_t    *peer;
0080 };
0081 
0082 
0083 #if (NGX_HTTP_UPSTREAM_ZONE)
0084 
0085 #define ngx_http_upstream_rr_peers_rlock(peers)                               \
0086                                                                               \
0087     if (peers->shpool) {                                                      \
0088         ngx_rwlock_rlock(&peers->rwlock);                                     \
0089     }
0090 
0091 #define ngx_http_upstream_rr_peers_wlock(peers)                               \
0092                                                                               \
0093     if (peers->shpool) {                                                      \
0094         ngx_rwlock_wlock(&peers->rwlock);                                     \
0095     }
0096 
0097 #define ngx_http_upstream_rr_peers_unlock(peers)                              \
0098                                                                               \
0099     if (peers->shpool) {                                                      \
0100         ngx_rwlock_unlock(&peers->rwlock);                                    \
0101     }
0102 
0103 
0104 #define ngx_http_upstream_rr_peer_lock(peers, peer)                           \
0105                                                                               \
0106     if (peers->shpool) {                                                      \
0107         ngx_rwlock_wlock(&peer->lock);                                        \
0108     }
0109 
0110 #define ngx_http_upstream_rr_peer_unlock(peers, peer)                         \
0111                                                                               \
0112     if (peers->shpool) {                                                      \
0113         ngx_rwlock_unlock(&peer->lock);                                       \
0114     }
0115 
0116 #else
0117 
0118 #define ngx_http_upstream_rr_peers_rlock(peers)
0119 #define ngx_http_upstream_rr_peers_wlock(peers)
0120 #define ngx_http_upstream_rr_peers_unlock(peers)
0121 #define ngx_http_upstream_rr_peer_lock(peers, peer)
0122 #define ngx_http_upstream_rr_peer_unlock(peers, peer)
0123 
0124 #endif
0125 
0126 
0127 typedef struct {
0128     ngx_uint_t                      config;
0129     ngx_http_upstream_rr_peers_t   *peers;
0130     ngx_http_upstream_rr_peer_t    *current;
0131     uintptr_t                      *tried;
0132     uintptr_t                       data;
0133 } ngx_http_upstream_rr_peer_data_t;
0134 
0135 
0136 ngx_int_t ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
0137     ngx_http_upstream_srv_conf_t *us);
0138 ngx_int_t ngx_http_upstream_init_round_robin_peer(ngx_http_request_t *r,
0139     ngx_http_upstream_srv_conf_t *us);
0140 ngx_int_t ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
0141     ngx_http_upstream_resolved_t *ur);
0142 ngx_int_t ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc,
0143     void *data);
0144 void ngx_http_upstream_free_round_robin_peer(ngx_peer_connection_t *pc,
0145     void *data, ngx_uint_t state);
0146 
0147 #if (NGX_HTTP_SSL)
0148 ngx_int_t
0149     ngx_http_upstream_set_round_robin_peer_session(ngx_peer_connection_t *pc,
0150     void *data);
0151 void ngx_http_upstream_save_round_robin_peer_session(ngx_peer_connection_t *pc,
0152     void *data);
0153 #endif
0154 
0155 
0156 #endif /* _NGX_HTTP_UPSTREAM_ROUND_ROBIN_H_INCLUDED_ */