Mercurial > hg > nginx
comparison src/http/modules/ngx_http_limit_req_module.c @ 4515:8bb695c05870 stable-1.0
Merge of r4498:
Fix of rbtree lookup on hash collisions.
Previous code incorrectly assumed that nodes with identical keys are linked
together. This might not be true after tree rebalance.
Patch by Lanshun Zhou.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 05 Mar 2012 13:17:56 +0000 |
parents | 4919fb357a5d |
children | 50143b8fb95f |
comparison
equal
deleted
inserted
replaced
4514:79142134d616 | 4515:8bb695c05870 |
---|---|
370 continue; | 370 continue; |
371 } | 371 } |
372 | 372 |
373 /* hash == node->key */ | 373 /* hash == node->key */ |
374 | 374 |
375 do { | 375 lr = (ngx_http_limit_req_node_t *) &node->color; |
376 lr = (ngx_http_limit_req_node_t *) &node->color; | 376 |
377 | 377 rc = ngx_memn2cmp(data, lr->data, len, (size_t) lr->len); |
378 rc = ngx_memn2cmp(data, lr->data, len, (size_t) lr->len); | 378 |
379 | 379 if (rc == 0) { |
380 if (rc == 0) { | 380 ngx_queue_remove(&lr->queue); |
381 ngx_queue_remove(&lr->queue); | 381 ngx_queue_insert_head(&ctx->sh->queue, &lr->queue); |
382 ngx_queue_insert_head(&ctx->sh->queue, &lr->queue); | 382 |
383 | 383 tp = ngx_timeofday(); |
384 tp = ngx_timeofday(); | 384 |
385 | 385 now = (ngx_msec_t) (tp->sec * 1000 + tp->msec); |
386 now = (ngx_msec_t) (tp->sec * 1000 + tp->msec); | 386 ms = (ngx_msec_int_t) (now - lr->last); |
387 ms = (ngx_msec_int_t) (now - lr->last); | 387 |
388 | 388 excess = lr->excess - ctx->rate * ngx_abs(ms) / 1000 + 1000; |
389 excess = lr->excess - ctx->rate * ngx_abs(ms) / 1000 + 1000; | 389 |
390 | 390 if (excess < 0) { |
391 if (excess < 0) { | 391 excess = 0; |
392 excess = 0; | 392 } |
393 } | 393 |
394 | 394 *ep = excess; |
395 *ep = excess; | 395 |
396 | 396 if ((ngx_uint_t) excess > lrcf->burst) { |
397 if ((ngx_uint_t) excess > lrcf->burst) { | 397 return NGX_BUSY; |
398 return NGX_BUSY; | 398 } |
399 } | 399 |
400 | 400 lr->excess = excess; |
401 lr->excess = excess; | 401 lr->last = now; |
402 lr->last = now; | 402 |
403 | 403 if (excess) { |
404 if (excess) { | 404 return NGX_AGAIN; |
405 return NGX_AGAIN; | 405 } |
406 } | 406 |
407 | 407 return NGX_OK; |
408 return NGX_OK; | 408 } |
409 } | 409 |
410 | 410 node = (rc < 0) ? node->left : node->right; |
411 node = (rc < 0) ? node->left : node->right; | |
412 | |
413 } while (node != sentinel && hash == node->key); | |
414 | |
415 break; | |
416 } | 411 } |
417 | 412 |
418 *ep = 0; | 413 *ep = 0; |
419 | 414 |
420 return NGX_DECLINED; | 415 return NGX_DECLINED; |