optimize $r->sleep
diff --git a/src/http/modules/perl/nginx.xs b/src/http/modules/perl/nginx.xs
index f3948e2..ea8c366 100644
--- a/src/http/modules/perl/nginx.xs
+++ b/src/http/modules/perl/nginx.xs
@@ -934,17 +934,23 @@
CODE:
ngx_http_request_t *r;
+ ngx_msec_t sleep;
ngx_http_perl_ctx_t *ctx;
ngx_http_perl_set_request(r);
- ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
-
- ctx->sleep = SvIV(ST(1));
- ctx->next = SvRV(ST(2));
+ sleep = SvIV(ST(1));
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "perl sleep: %d", ctx->sleep);
+ "perl sleep: %M", sleep);
+
+ ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
+
+ ctx->next = SvRV(ST(2));
+
+ ngx_add_timer(r->connection->write, sleep);
+
+ r->write_event_handler = ngx_http_perl_sleep_handler;
void
diff --git a/src/http/modules/perl/ngx_http_perl_module.c b/src/http/modules/perl/ngx_http_perl_module.c
index 07dad1c..32d996a 100644
--- a/src/http/modules/perl/ngx_http_perl_module.c
+++ b/src/http/modules/perl/ngx_http_perl_module.c
@@ -41,7 +41,6 @@
ngx_http_ssi_ctx_t *ssi_ctx, ngx_str_t **params);
#endif
-static void ngx_http_perl_sleep_handler(ngx_http_request_t *r);
static char *ngx_http_perl_init_interpreter(ngx_conf_t *cf,
ngx_http_perl_main_conf_t *pmcf);
static PerlInterpreter *ngx_http_perl_create_interpreter(ngx_conf_t *cf,
@@ -252,12 +251,6 @@
ctx->filename.data = NULL;
ctx->redirect_uri.len = 0;
- if (ctx->sleep) {
- ngx_add_timer(r->connection->write, (ngx_msec_t) ctx->sleep);
- r->write_event_handler = ngx_http_perl_sleep_handler;
- ctx->sleep = 0;
- }
-
if (ctx->done || ctx->next) {
return;
}
@@ -276,7 +269,7 @@
}
-static void
+void
ngx_http_perl_sleep_handler(ngx_http_request_t *r)
{
ngx_event_t *wev;
diff --git a/src/http/modules/perl/ngx_http_perl_module.h b/src/http/modules/perl/ngx_http_perl_module.h
index 6ae63e8..23969bc 100644
--- a/src/http/modules/perl/ngx_http_perl_module.h
+++ b/src/http/modules/perl/ngx_http_perl_module.h
@@ -25,9 +25,8 @@
ngx_str_t redirect_args;
SV *next;
- int sleep;
- ngx_uint_t done; /* unsigned done:1; */
+ ngx_uint_t done; /* unsigned done:1; */
ngx_array_t *variables; /* array of ngx_http_perl_var_t */
@@ -61,6 +60,7 @@
void ngx_http_perl_handle_request(ngx_http_request_t *r);
+void ngx_http_perl_sleep_handler(ngx_http_request_t *r);
#endif /* _NGX_HTTP_PERL_MODULE_H_INCLUDED_ */