Simplified extraction of current time.

This commit is contained in:
Ruslan Ermilov 2016-08-08 17:11:29 +03:00
parent af9e72533a
commit 47e72bf7e0
2 changed files with 8 additions and 16 deletions

View File

@ -362,15 +362,13 @@ ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, ngx_uint_t hash,
{ {
size_t size; size_t size;
ngx_int_t rc, excess; ngx_int_t rc, excess;
ngx_time_t *tp;
ngx_msec_t now; ngx_msec_t now;
ngx_msec_int_t ms; ngx_msec_int_t ms;
ngx_rbtree_node_t *node, *sentinel; ngx_rbtree_node_t *node, *sentinel;
ngx_http_limit_req_ctx_t *ctx; ngx_http_limit_req_ctx_t *ctx;
ngx_http_limit_req_node_t *lr; ngx_http_limit_req_node_t *lr;
tp = ngx_timeofday(); now = ngx_current_msec;
now = (ngx_msec_t) (tp->sec * 1000 + tp->msec);
ctx = limit->shm_zone->data; ctx = limit->shm_zone->data;
@ -483,7 +481,6 @@ ngx_http_limit_req_account(ngx_http_limit_req_limit_t *limits, ngx_uint_t n,
ngx_uint_t *ep, ngx_http_limit_req_limit_t **limit) ngx_uint_t *ep, ngx_http_limit_req_limit_t **limit)
{ {
ngx_int_t excess; ngx_int_t excess;
ngx_time_t *tp;
ngx_msec_t now, delay, max_delay; ngx_msec_t now, delay, max_delay;
ngx_msec_int_t ms; ngx_msec_int_t ms;
ngx_http_limit_req_ctx_t *ctx; ngx_http_limit_req_ctx_t *ctx;
@ -509,9 +506,7 @@ ngx_http_limit_req_account(ngx_http_limit_req_limit_t *limits, ngx_uint_t n,
ngx_shmtx_lock(&ctx->shpool->mutex); ngx_shmtx_lock(&ctx->shpool->mutex);
tp = ngx_timeofday(); now = ngx_current_msec;
now = (ngx_msec_t) (tp->sec * 1000 + tp->msec);
ms = (ngx_msec_int_t) (now - lr->last); ms = (ngx_msec_int_t) (now - lr->last);
excess = lr->excess - ctx->rate * ngx_abs(ms) / 1000 + 1000; excess = lr->excess - ctx->rate * ngx_abs(ms) / 1000 + 1000;
@ -549,16 +544,13 @@ static void
ngx_http_limit_req_expire(ngx_http_limit_req_ctx_t *ctx, ngx_uint_t n) ngx_http_limit_req_expire(ngx_http_limit_req_ctx_t *ctx, ngx_uint_t n)
{ {
ngx_int_t excess; ngx_int_t excess;
ngx_time_t *tp;
ngx_msec_t now; ngx_msec_t now;
ngx_queue_t *q; ngx_queue_t *q;
ngx_msec_int_t ms; ngx_msec_int_t ms;
ngx_rbtree_node_t *node; ngx_rbtree_node_t *node;
ngx_http_limit_req_node_t *lr; ngx_http_limit_req_node_t *lr;
tp = ngx_timeofday(); now = ngx_current_msec;
now = (ngx_msec_t) (tp->sec * 1000 + tp->msec);
/* /*
* n == 1 deletes one or two zero rate entries * n == 1 deletes one or two zero rate entries

View File

@ -2722,8 +2722,8 @@ static ngx_int_t
ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r, ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t gmt) ngx_http_variable_value_t *v, uintptr_t gmt)
{ {
time_t now;
ngx_http_ssi_ctx_t *ctx; ngx_http_ssi_ctx_t *ctx;
ngx_time_t *tp;
ngx_str_t *timefmt; ngx_str_t *timefmt;
struct tm tm; struct tm tm;
char buf[NGX_HTTP_SSI_DATE_LEN]; char buf[NGX_HTTP_SSI_DATE_LEN];
@ -2732,7 +2732,7 @@ ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r,
v->no_cacheable = 0; v->no_cacheable = 0;
v->not_found = 0; v->not_found = 0;
tp = ngx_timeofday(); now = ngx_time();
ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module); ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module);
@ -2746,15 +2746,15 @@ ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r,
return NGX_ERROR; return NGX_ERROR;
} }
v->len = ngx_sprintf(v->data, "%T", tp->sec) - v->data; v->len = ngx_sprintf(v->data, "%T", now) - v->data;
return NGX_OK; return NGX_OK;
} }
if (gmt) { if (gmt) {
ngx_libc_gmtime(tp->sec, &tm); ngx_libc_gmtime(now, &tm);
} else { } else {
ngx_libc_localtime(tp->sec, &tm); ngx_libc_localtime(now, &tm);
} }
v->len = strftime(buf, NGX_HTTP_SSI_DATE_LEN, v->len = strftime(buf, NGX_HTTP_SSI_DATE_LEN,