]> git.kaiwu.me - nginx.git/commitdiff
optimize $r->sleep
authorIgor Sysoev <igor@sysoev.ru>
Sat, 16 Feb 2008 14:23:14 +0000 (14:23 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Sat, 16 Feb 2008 14:23:14 +0000 (14:23 +0000)
src/http/modules/perl/nginx.xs
src/http/modules/perl/ngx_http_perl_module.c
src/http/modules/perl/ngx_http_perl_module.h

index f3948e2701be7f3e378aa822c08452475ec93a44..ea8c366df02318025cdc360531ac8d35d5970b9b 100644 (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);
 
+    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
index 07dad1c815dea46f62a8f70f3e43b9b7f188c6dc..32d996a673a0965596ea3c827d85ffeab58986ca 100644 (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;
index 6ae63e820f1db2f9628cce0792f5bb570d9d84f5..23969bcd485e9ed39746ee8bf69642953cad18cc 100644 (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_ */