comparison src/http/modules/ngx_http_split_clients_module.c @ 4561:ae63013cbffa

Fixed calculation of range boundaries.
author Ruslan Ermilov <ru@nginx.com>
date Wed, 28 Mar 2012 06:50:23 +0000
parents d620f497c50f
children 834049edae24
comparison
equal deleted inserted replaced
4560:1a11e4a8877a 4561:ae63013cbffa
95 for (i = 0; i < ctx->parts.nelts; i++) { 95 for (i = 0; i < ctx->parts.nelts; i++) {
96 96
97 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 97 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
98 "http split: %uD %uD", hash, part[i].percent); 98 "http split: %uD %uD", hash, part[i].percent);
99 99
100 if (hash < part[i].percent) { 100 if (hash < part[i].percent || part[i].percent == 0) {
101 *v = part[i].value; 101 *v = part[i].value;
102 return NGX_OK; 102 return NGX_OK;
103 } 103 }
104 } 104 }
105 105
109 109
110 static char * 110 static char *
111 ngx_conf_split_clients_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 111 ngx_conf_split_clients_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
112 { 112 {
113 char *rv; 113 char *rv;
114 uint32_t sum, last;
114 ngx_str_t *value, name; 115 ngx_str_t *value, name;
115 ngx_uint_t i, sum, last; 116 ngx_uint_t i;
116 ngx_conf_t save; 117 ngx_conf_t save;
117 ngx_http_variable_t *var; 118 ngx_http_variable_t *var;
118 ngx_http_split_clients_ctx_t *ctx; 119 ngx_http_split_clients_ctx_t *ctx;
119 ngx_http_split_clients_part_t *part; 120 ngx_http_split_clients_part_t *part;
120 ngx_http_compile_complex_value_t ccv; 121 ngx_http_compile_complex_value_t ccv;
173 part = ctx->parts.elts; 174 part = ctx->parts.elts;
174 175
175 for (i = 0; i < ctx->parts.nelts; i++) { 176 for (i = 0; i < ctx->parts.nelts; i++) {
176 sum = part[i].percent ? sum + part[i].percent : 10000; 177 sum = part[i].percent ? sum + part[i].percent : 10000;
177 if (sum > 10000) { 178 if (sum > 10000) {
178 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 179 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
179 "percent sum is more than 100%%"); 180 "percent sum is more than 100%%");
180 return NGX_CONF_ERROR; 181 return NGX_CONF_ERROR;
181 } 182 }
182 183
183 if (part[i].percent) { 184 if (part[i].percent) {
184 part[i].percent = (uint32_t) 185 last += part[i].percent * (uint64_t) 0xffffffff / 10000;
185 (last + 0xffffffff / 10000 * part[i].percent); 186 part[i].percent = last;
186 } else { 187 }
187 part[i].percent = 0xffffffff;
188 }
189
190 last = part[i].percent;
191 } 188 }
192 189
193 return rv; 190 return rv;
194 } 191 }
195 192