optimize $r->sleep

This commit is contained in:
Igor Sysoev 2008-02-16 14:23:14 +00:00
parent 5fa1146dd5
commit 0a0c02f58b
3 changed files with 14 additions and 15 deletions

View File

@ -934,17 +934,23 @@ sleep(r, sleep, next)
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

View File

@ -41,7 +41,6 @@ static ngx_int_t ngx_http_perl_ssi(ngx_http_request_t *r,
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 @@ ngx_http_perl_handle_request(ngx_http_request_t *r)
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 @@ ngx_http_perl_handle_request(ngx_http_request_t *r)
}
static void
void
ngx_http_perl_sleep_handler(ngx_http_request_t *r)
{
ngx_event_t *wev;

View File

@ -25,9 +25,8 @@ typedef struct {
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 @@ extern void boot_DynaLoader(pTHX_ CV* cv);
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_ */