# HG changeset patch # User Igor Sysoev # Date 1203171794 0 # Node ID b43f244d043039d6f0c870da825af62dfdc3bbb6 # Parent 4c060e30476b69e0ad558ccab67b2da7aa95e17d optimize $r->sleep diff -r 4c060e30476b -r b43f244d0430 src/http/modules/perl/nginx.xs --- a/src/http/modules/perl/nginx.xs Sat Feb 16 13:46:33 2008 +0000 +++ b/src/http/modules/perl/nginx.xs Sat Feb 16 14:23:14 2008 +0000 @@ -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); + sleep = SvIV(ST(1)); + + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "perl sleep: %M", sleep); + ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); - ctx->sleep = SvIV(ST(1)); ctx->next = SvRV(ST(2)); - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "perl sleep: %d", ctx->sleep); + ngx_add_timer(r->connection->write, sleep); + + r->write_event_handler = ngx_http_perl_sleep_handler; void diff -r 4c060e30476b -r b43f244d0430 src/http/modules/perl/ngx_http_perl_module.c --- a/src/http/modules/perl/ngx_http_perl_module.c Sat Feb 16 13:46:33 2008 +0000 +++ b/src/http/modules/perl/ngx_http_perl_module.c Sat Feb 16 14:23:14 2008 +0000 @@ -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 -r 4c060e30476b -r b43f244d0430 src/http/modules/perl/ngx_http_perl_module.h --- a/src/http/modules/perl/ngx_http_perl_module.h Sat Feb 16 13:46:33 2008 +0000 +++ b/src/http/modules/perl/ngx_http_perl_module.h Sat Feb 16 14:23:14 2008 +0000 @@ -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_ */