Klaus Demo nginx / 7a8e339
sort upstream weights Igor Sysoev 13 years ago
1 changed file(s) with 21 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
88 #include <ngx_http.h>
99
1010
11 static int ngx_http_upstream_cmp_servers(const void *one, const void *two);
1112 static ngx_uint_t
1213 ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers);
1314
6869
6970 us->peer.data = peers;
7071
72 ngx_sort(&peers->peer[0], (size_t) n,
73 sizeof(ngx_http_upstream_rr_peer_t),
74 ngx_http_upstream_cmp_servers);
75
7176 /* backup servers */
7277
7378 n = 0;
117122
118123 peers->next = backup;
119124
125 ngx_sort(&backup->peer[0], (size_t) n,
126 sizeof(ngx_http_upstream_rr_peer_t),
127 ngx_http_upstream_cmp_servers);
128
120129 return NGX_OK;
121130 }
122131
178187 }
179188
180189
190 static int
191 ngx_http_upstream_cmp_servers(const void *one, const void *two)
192 {
193 ngx_http_upstream_rr_peer_t *first, *second;
194
195 first = (ngx_http_upstream_rr_peer_t *) one;
196 second = (ngx_http_upstream_rr_peer_t *) two;
197
198 return (first->weight < second->weight);
199 }
200
201
181202 ngx_int_t
182203 ngx_http_upstream_init_round_robin_peer(ngx_http_request_t *r,
183204 ngx_http_upstream_srv_conf_t *us)