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_STREAM_UPSTREAM_ROUND_ROBIN_H_INCLUDED_
0009 #define _NGX_STREAM_UPSTREAM_ROUND_ROBIN_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 #include <ngx_stream.h>
0015 
0016 
0017 typedef struct ngx_stream_upstream_rr_peer_s   ngx_stream_upstream_rr_peer_t;
0018 
0019 struct ngx_stream_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     void                            *ssl_session;
0044     int                              ssl_session_len;
0045 
0046 #if (NGX_STREAM_UPSTREAM_ZONE)
0047     ngx_atomic_t                     lock;
0048 #endif
0049 
0050     ngx_stream_upstream_rr_peer_t   *next;
0051 
0052     NGX_COMPAT_BEGIN(25)
0053     NGX_COMPAT_END
0054 };
0055 
0056 
0057 typedef struct ngx_stream_upstream_rr_peers_s  ngx_stream_upstream_rr_peers_t;
0058 
0059 struct ngx_stream_upstream_rr_peers_s {
0060     ngx_uint_t                       number;
0061 
0062 #if (NGX_STREAM_UPSTREAM_ZONE)
0063     ngx_slab_pool_t                 *shpool;
0064     ngx_atomic_t                     rwlock;
0065     ngx_stream_upstream_rr_peers_t  *zone_next;
0066 #endif
0067 
0068     ngx_uint_t                       total_weight;
0069 
0070     unsigned                         single:1;
0071     unsigned                         weighted:1;
0072 
0073     ngx_str_t                       *name;
0074 
0075     ngx_stream_upstream_rr_peers_t  *next;
0076 
0077     ngx_stream_upstream_rr_peer_t   *peer;
0078 };
0079 
0080 
0081 #if (NGX_STREAM_UPSTREAM_ZONE)
0082 
0083 #define ngx_stream_upstream_rr_peers_rlock(peers)                             \
0084                                                                               \
0085     if (peers->shpool) {                                                      \
0086         ngx_rwlock_rlock(&peers->rwlock);                                     \
0087     }
0088 
0089 #define ngx_stream_upstream_rr_peers_wlock(peers)                             \
0090                                                                               \
0091     if (peers->shpool) {                                                      \
0092         ngx_rwlock_wlock(&peers->rwlock);                                     \
0093     }
0094 
0095 #define ngx_stream_upstream_rr_peers_unlock(peers)                            \
0096                                                                               \
0097     if (peers->shpool) {                                                      \
0098         ngx_rwlock_unlock(&peers->rwlock);                                    \
0099     }
0100 
0101 
0102 #define ngx_stream_upstream_rr_peer_lock(peers, peer)                         \
0103                                                                               \
0104     if (peers->shpool) {                                                      \
0105         ngx_rwlock_wlock(&peer->lock);                                        \
0106     }
0107 
0108 #define ngx_stream_upstream_rr_peer_unlock(peers, peer)                       \
0109                                                                               \
0110     if (peers->shpool) {                                                      \
0111         ngx_rwlock_unlock(&peer->lock);                                       \
0112     }
0113 
0114 #else
0115 
0116 #define ngx_stream_upstream_rr_peers_rlock(peers)
0117 #define ngx_stream_upstream_rr_peers_wlock(peers)
0118 #define ngx_stream_upstream_rr_peers_unlock(peers)
0119 #define ngx_stream_upstream_rr_peer_lock(peers, peer)
0120 #define ngx_stream_upstream_rr_peer_unlock(peers, peer)
0121 
0122 #endif
0123 
0124 
0125 typedef struct {
0126     ngx_uint_t                       config;
0127     ngx_stream_upstream_rr_peers_t  *peers;
0128     ngx_stream_upstream_rr_peer_t   *current;
0129     uintptr_t                       *tried;
0130     uintptr_t                        data;
0131 } ngx_stream_upstream_rr_peer_data_t;
0132 
0133 
0134 ngx_int_t ngx_stream_upstream_init_round_robin(ngx_conf_t *cf,
0135     ngx_stream_upstream_srv_conf_t *us);
0136 ngx_int_t ngx_stream_upstream_init_round_robin_peer(ngx_stream_session_t *s,
0137     ngx_stream_upstream_srv_conf_t *us);
0138 ngx_int_t ngx_stream_upstream_create_round_robin_peer(ngx_stream_session_t *s,
0139     ngx_stream_upstream_resolved_t *ur);
0140 ngx_int_t ngx_stream_upstream_get_round_robin_peer(ngx_peer_connection_t *pc,
0141     void *data);
0142 void ngx_stream_upstream_free_round_robin_peer(ngx_peer_connection_t *pc,
0143     void *data, ngx_uint_t state);
0144 
0145 
0146 #endif /* _NGX_STREAM_UPSTREAM_ROUND_ROBIN_H_INCLUDED_ */