[nginx] Simplified extraction of current time.

Ruslan Ermilov ru at nginx.com
Wed Aug 10 12:53:04 UTC 2016


details:   http://hg.nginx.org/nginx/rev/7a6456398fc3
branches:  
changeset: 6653:7a6456398fc3
user:      Ruslan Ermilov <ru at nginx.com>
date:      Mon Aug 08 17:11:29 2016 +0300
description:
Simplified extraction of current time.

diffstat:

 src/http/modules/ngx_http_limit_req_module.c  |  14 +++-----------
 src/http/modules/ngx_http_ssi_filter_module.c |  10 +++++-----
 2 files changed, 8 insertions(+), 16 deletions(-)

diffs (98 lines):

diff -r 1891b2892b68 -r 7a6456398fc3 src/http/modules/ngx_http_limit_req_module.c
--- a/src/http/modules/ngx_http_limit_req_module.c	Mon Aug 08 13:44:49 2016 +0300
+++ b/src/http/modules/ngx_http_limit_req_module.c	Mon Aug 08 17:11:29 2016 +0300
@@ -362,15 +362,13 @@ ngx_http_limit_req_lookup(ngx_http_limit
 {
     size_t                      size;
     ngx_int_t                   rc, excess;
-    ngx_time_t                 *tp;
     ngx_msec_t                  now;
     ngx_msec_int_t              ms;
     ngx_rbtree_node_t          *node, *sentinel;
     ngx_http_limit_req_ctx_t   *ctx;
     ngx_http_limit_req_node_t  *lr;
 
-    tp = ngx_timeofday();
-    now = (ngx_msec_t) (tp->sec * 1000 + tp->msec);
+    now = ngx_current_msec;
 
     ctx = limit->shm_zone->data;
 
@@ -483,7 +481,6 @@ ngx_http_limit_req_account(ngx_http_limi
     ngx_uint_t *ep, ngx_http_limit_req_limit_t **limit)
 {
     ngx_int_t                   excess;
-    ngx_time_t                 *tp;
     ngx_msec_t                  now, delay, max_delay;
     ngx_msec_int_t              ms;
     ngx_http_limit_req_ctx_t   *ctx;
@@ -509,9 +506,7 @@ ngx_http_limit_req_account(ngx_http_limi
 
         ngx_shmtx_lock(&ctx->shpool->mutex);
 
-        tp = ngx_timeofday();
-
-        now = (ngx_msec_t) (tp->sec * 1000 + tp->msec);
+        now = ngx_current_msec;
         ms = (ngx_msec_int_t) (now - lr->last);
 
         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_int_t                   excess;
-    ngx_time_t                 *tp;
     ngx_msec_t                  now;
     ngx_queue_t                *q;
     ngx_msec_int_t              ms;
     ngx_rbtree_node_t          *node;
     ngx_http_limit_req_node_t  *lr;
 
-    tp = ngx_timeofday();
-
-    now = (ngx_msec_t) (tp->sec * 1000 + tp->msec);
+    now = ngx_current_msec;
 
     /*
      * n == 1 deletes one or two zero rate entries
diff -r 1891b2892b68 -r 7a6456398fc3 src/http/modules/ngx_http_ssi_filter_module.c
--- a/src/http/modules/ngx_http_ssi_filter_module.c	Mon Aug 08 13:44:49 2016 +0300
+++ b/src/http/modules/ngx_http_ssi_filter_module.c	Mon Aug 08 17:11:29 2016 +0300
@@ -2722,8 +2722,8 @@ static ngx_int_t
 ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t gmt)
 {
+    time_t               now;
     ngx_http_ssi_ctx_t  *ctx;
-    ngx_time_t          *tp;
     ngx_str_t           *timefmt;
     struct tm            tm;
     char                 buf[NGX_HTTP_SSI_DATE_LEN];
@@ -2732,7 +2732,7 @@ ngx_http_ssi_date_gmt_local_variable(ngx
     v->no_cacheable = 0;
     v->not_found = 0;
 
-    tp = ngx_timeofday();
+    now = ngx_time();
 
     ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module);
 
@@ -2746,15 +2746,15 @@ ngx_http_ssi_date_gmt_local_variable(ngx
             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;
     }
 
     if (gmt) {
-        ngx_libc_gmtime(tp->sec, &tm);
+        ngx_libc_gmtime(now, &tm);
     } else {
-        ngx_libc_localtime(tp->sec, &tm);
+        ngx_libc_localtime(now, &tm);
     }
 
     v->len = strftime(buf, NGX_HTTP_SSI_DATE_LEN,



More information about the nginx-devel mailing list