Mercurial > hg > nginx
comparison src/http/modules/ngx_http_limit_req_module.c @ 5863:102f85699420
Limit req: reduced number of parameters in the lookup function.
No functional changes.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Wed, 24 Sep 2014 21:55:19 +0400 |
parents | ecbb99aa0e12 |
children | 3b7a60371a9a |
comparison
equal
deleted
inserted
replaced
5862:ecbb99aa0e12 | 5863:102f85699420 |
---|---|
56 } ngx_http_limit_req_conf_t; | 56 } ngx_http_limit_req_conf_t; |
57 | 57 |
58 | 58 |
59 static void ngx_http_limit_req_delay(ngx_http_request_t *r); | 59 static void ngx_http_limit_req_delay(ngx_http_request_t *r); |
60 static ngx_int_t ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, | 60 static ngx_int_t ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, |
61 ngx_uint_t hash, u_char *data, size_t len, ngx_uint_t *ep, | 61 ngx_uint_t hash, ngx_str_t *key, ngx_uint_t *ep, ngx_uint_t account); |
62 ngx_uint_t account); | |
63 static ngx_msec_t ngx_http_limit_req_account(ngx_http_limit_req_limit_t *limits, | 62 static ngx_msec_t ngx_http_limit_req_account(ngx_http_limit_req_limit_t *limits, |
64 ngx_uint_t n, ngx_uint_t *ep, ngx_http_limit_req_limit_t **limit); | 63 ngx_uint_t n, ngx_uint_t *ep, ngx_http_limit_req_limit_t **limit); |
65 static void ngx_http_limit_req_expire(ngx_http_limit_req_ctx_t *ctx, | 64 static void ngx_http_limit_req_expire(ngx_http_limit_req_ctx_t *ctx, |
66 ngx_uint_t n); | 65 ngx_uint_t n); |
67 | 66 |
205 | 204 |
206 hash = ngx_crc32_short(key.data, key.len); | 205 hash = ngx_crc32_short(key.data, key.len); |
207 | 206 |
208 ngx_shmtx_lock(&ctx->shpool->mutex); | 207 ngx_shmtx_lock(&ctx->shpool->mutex); |
209 | 208 |
210 rc = ngx_http_limit_req_lookup(limit, hash, key.data, key.len, &excess, | 209 rc = ngx_http_limit_req_lookup(limit, hash, &key, &excess, |
211 (n == lrcf->limits.nelts - 1)); | 210 (n == lrcf->limits.nelts - 1)); |
212 | 211 |
213 ngx_shmtx_unlock(&ctx->shpool->mutex); | 212 ngx_shmtx_unlock(&ctx->shpool->mutex); |
214 | 213 |
215 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 214 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
357 } | 356 } |
358 | 357 |
359 | 358 |
360 static ngx_int_t | 359 static ngx_int_t |
361 ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, ngx_uint_t hash, | 360 ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, ngx_uint_t hash, |
362 u_char *data, size_t len, ngx_uint_t *ep, ngx_uint_t account) | 361 ngx_str_t *key, ngx_uint_t *ep, ngx_uint_t account) |
363 { | 362 { |
364 size_t size; | 363 size_t size; |
365 ngx_int_t rc, excess; | 364 ngx_int_t rc, excess; |
366 ngx_time_t *tp; | 365 ngx_time_t *tp; |
367 ngx_msec_t now; | 366 ngx_msec_t now; |
392 | 391 |
393 /* hash == node->key */ | 392 /* hash == node->key */ |
394 | 393 |
395 lr = (ngx_http_limit_req_node_t *) &node->color; | 394 lr = (ngx_http_limit_req_node_t *) &node->color; |
396 | 395 |
397 rc = ngx_memn2cmp(data, lr->data, len, (size_t) lr->len); | 396 rc = ngx_memn2cmp(key->data, lr->data, key->len, (size_t) lr->len); |
398 | 397 |
399 if (rc == 0) { | 398 if (rc == 0) { |
400 ngx_queue_remove(&lr->queue); | 399 ngx_queue_remove(&lr->queue); |
401 ngx_queue_insert_head(&ctx->sh->queue, &lr->queue); | 400 ngx_queue_insert_head(&ctx->sh->queue, &lr->queue); |
402 | 401 |
432 | 431 |
433 *ep = 0; | 432 *ep = 0; |
434 | 433 |
435 size = offsetof(ngx_rbtree_node_t, color) | 434 size = offsetof(ngx_rbtree_node_t, color) |
436 + offsetof(ngx_http_limit_req_node_t, data) | 435 + offsetof(ngx_http_limit_req_node_t, data) |
437 + len; | 436 + key->len; |
438 | 437 |
439 ngx_http_limit_req_expire(ctx, 1); | 438 ngx_http_limit_req_expire(ctx, 1); |
440 | 439 |
441 node = ngx_slab_alloc_locked(ctx->shpool, size); | 440 node = ngx_slab_alloc_locked(ctx->shpool, size); |
442 | 441 |
453 | 452 |
454 node->key = hash; | 453 node->key = hash; |
455 | 454 |
456 lr = (ngx_http_limit_req_node_t *) &node->color; | 455 lr = (ngx_http_limit_req_node_t *) &node->color; |
457 | 456 |
458 lr->len = (u_short) len; | 457 lr->len = (u_short) key->len; |
459 lr->excess = 0; | 458 lr->excess = 0; |
460 | 459 |
461 ngx_memcpy(lr->data, data, len); | 460 ngx_memcpy(lr->data, key->data, key->len); |
462 | 461 |
463 ngx_rbtree_insert(&ctx->sh->rbtree, node); | 462 ngx_rbtree_insert(&ctx->sh->rbtree, node); |
464 | 463 |
465 ngx_queue_insert_head(&ctx->sh->queue, &lr->queue); | 464 ngx_queue_insert_head(&ctx->sh->queue, &lr->queue); |
466 | 465 |