-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jianhao.dai
committed
May 1, 2018
1 parent
ddb4d68
commit c2b2427
Showing
4 changed files
with
174 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
diff --git a/src/ngx_http_lua_time.c b/src/ngx_http_lua_time.c | ||
index 3272a75..d6ff7e4 100644 | ||
--- a/src/ngx_http_lua_time.c | ||
+++ b/src/ngx_http_lua_time.c | ||
@@ -17,6 +17,7 @@ | ||
|
||
static int ngx_http_lua_ngx_today(lua_State *L); | ||
static int ngx_http_lua_ngx_time(lua_State *L); | ||
+static int ngx_http_lua_ngx_usec_time(lua_State *L); | ||
static int ngx_http_lua_ngx_now(lua_State *L); | ||
static int ngx_http_lua_ngx_localtime(lua_State *L); | ||
static int ngx_http_lua_ngx_utctime(lua_State *L); | ||
@@ -75,6 +76,19 @@ ngx_http_lua_ngx_time(lua_State *L) | ||
|
||
|
||
static int | ||
+ngx_http_lua_ngx_usec_time(lua_State *L) | ||
+{ | ||
+ ngx_time_t *tp; | ||
+ | ||
+ tp = ngx_timeofday(); | ||
+ | ||
+ lua_pushnumber(L, (lua_Number) tp->usec); | ||
+ | ||
+ return 1; | ||
+} | ||
+ | ||
+ | ||
+static int | ||
ngx_http_lua_ngx_now(lua_State *L) | ||
{ | ||
ngx_time_t *tp; | ||
@@ -217,6 +231,9 @@ ngx_http_lua_inject_time_api(lua_State *L) | ||
lua_pushcfunction(L, ngx_http_lua_ngx_time); | ||
lua_setfield(L, -2, "time"); | ||
|
||
+ lua_pushcfunction(L, ngx_http_lua_ngx_usec_time); | ||
+ lua_setfield(L, -2, "usec_time"); | ||
+ | ||
lua_pushcfunction(L, ngx_http_lua_ngx_now); | ||
lua_setfield(L, -2, "now"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- ../../../github/openresty/nginx-releases/src/core/ngx_times.c 2016-07-27 17:25:45.000000000 +0800 | ||
+++ nginx-1.9.15/src/core/ngx_times.c 2016-07-08 18:10:29.000000000 +0800 | ||
@@ -81,6 +81,7 @@ | ||
ngx_tm_t tm, gmt; | ||
time_t sec; | ||
ngx_uint_t msec; | ||
+ ngx_uint_t usec; | ||
ngx_time_t *tp; | ||
struct timeval tv; | ||
|
||
@@ -91,7 +92,8 @@ | ||
ngx_gettimeofday(&tv); | ||
|
||
sec = tv.tv_sec; | ||
- msec = tv.tv_usec / 1000; | ||
+ usec = tv.tv_usec; | ||
+ msec = usec / 1000; | ||
|
||
ngx_current_msec = (ngx_msec_t) sec * 1000 + msec; | ||
|
||
@@ -99,6 +101,7 @@ | ||
|
||
if (tp->sec == sec) { | ||
tp->msec = msec; | ||
+ tp->usec = usec; | ||
ngx_unlock(&ngx_time_lock); | ||
return; | ||
} | ||
@@ -113,6 +116,7 @@ | ||
|
||
tp->sec = sec; | ||
tp->msec = msec; | ||
+ tp->usec = usec; | ||
|
||
ngx_gmtime(sec, &gmt); | ||
|
||
--- ../../../github/openresty/nginx-releases/src/core/ngx_times.h 2016-07-27 17:25:45.000000000 +0800 | ||
+++ nginx-1.9.15/src/core/ngx_times.h 2016-07-08 18:10:50.000000000 +0800 | ||
@@ -16,6 +16,7 @@ | ||
typedef struct { | ||
time_t sec; | ||
ngx_uint_t msec; | ||
+ ngx_uint_t usec; | ||
ngx_int_t gmtoff; | ||
} ngx_time_t; | ||
|