diff --git a/src/ngx_http_echo_module.h b/src/ngx_http_echo_module.h index ce0a305..2f38802 100644 --- a/src/ngx_http_echo_module.h +++ b/src/ngx_http_echo_module.h @@ -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; diff --git a/src/ngx_http_echo_timer.c b/src/ngx_http_echo_timer.c index e2777ee..0b3cb80 100644 --- a/src/ngx_http_echo_timer.c +++ b/src/ngx_http_echo_timer.c @@ -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); @@ -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 */ @@ -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, @@ -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; @@ -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; }