Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ngx_http_echo_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ typedef struct {

ngx_http_echo_foreach_ctx_t *foreach;

#if (defined freenginx && nginx_version >= 1029000)
ngx_msec_t timer_begin;
#else
ngx_time_t timer_begin;
#endif

ngx_event_t sleep;

Expand Down
16 changes: 15 additions & 1 deletion src/ngx_http_echo_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ ngx_http_echo_timer_elapsed_variable(ngx_http_request_t *r,
ngx_http_echo_ctx_t *ctx;
ngx_msec_int_t ms;
u_char *p;
ngx_time_t *tp;
size_t size;

ctx = ngx_http_get_module_ctx(r, ngx_http_echo_module);
Expand All @@ -32,10 +31,15 @@ ngx_http_echo_timer_elapsed_variable(ngx_http_request_t *r,
ngx_http_set_ctx(r, ctx, ngx_http_echo_module);
}

#if (defined freenginx && nginx_version >= 1029000)
if (ctx->timer_begin == 0)
ctx->timer_begin = r->start_time;
#else
if (ctx->timer_begin.sec == 0) {
ctx->timer_begin.sec = r->start_sec;
ctx->timer_begin.msec = (ngx_msec_t) r->start_msec;
}
#endif

/* force the ngx timer to update */

Expand All @@ -45,6 +49,11 @@ ngx_http_echo_timer_elapsed_variable(ngx_http_request_t *r,
ngx_time_update(0, 0);
#endif

#if (defined freenginx && nginx_version >= 1029000)
ms = (ngx_msec_int_t) (ngx_current_msec - ctx->timer_begin);
#else
ngx_time_t *tp;

tp = ngx_timeofday();

dd("old sec msec: %ld %d\n", (long) ctx->timer_begin.sec,
Expand All @@ -55,6 +64,7 @@ ngx_http_echo_timer_elapsed_variable(ngx_http_request_t *r,
ms = (ngx_msec_int_t)
((tp->sec - ctx->timer_begin.sec) * 1000 +
(tp->msec - ctx->timer_begin.msec));
#endif
ms = (ms >= 0) ? ms : 0;

size = sizeof("-9223372036854775808.000") - 1;
Expand Down Expand Up @@ -89,7 +99,11 @@ ngx_http_echo_exec_echo_reset_timer(ngx_http_request_t *r,
ngx_time_update(0, 0);
#endif

#if (defined freenginx && nginx_version >= 1029000)
ctx->timer_begin = ngx_current_msec;
#else
ctx->timer_begin = *ngx_timeofday();
#endif
return NGX_OK;
}