diff src/http/modules/perl/ngx_http_perl_module.c @ 266:251bcd11a5b8 NGINX_0_5_3

nginx 0.5.3 *) Feature: the ngx_http_perl_module supports the $r->status, $r->log_error, and $r->sleep methods. *) Feature: the $r->variable method supports variables that do not exist in nginx configuration. *) Bugfix: the $r->has_request_body method did not work.
author Igor Sysoev <http://sysoev.ru>
date Wed, 13 Dec 2006 00:00:00 +0300
parents 6ae1357b7b7c
children a0c9f21ee120
line wrap: on
line diff
--- a/src/http/modules/perl/ngx_http_perl_module.c
+++ b/src/http/modules/perl/ngx_http_perl_module.c
@@ -41,6 +41,7 @@ static ngx_int_t ngx_http_perl_ssi(ngx_h
     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 *
@@ -62,7 +63,6 @@ static char *ngx_http_perl_require(ngx_c
     void *conf);
 static char *ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
 static char *ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
-static void ngx_http_perl_cleanup_sv(void *data);
 
 #if (NGX_HAVE_PERL_MULTIPLICITY)
 static void ngx_http_perl_cleanup_perl(void *data);
@@ -246,6 +246,12 @@ ngx_http_perl_handle_request(ngx_http_re
     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;
     }
@@ -264,6 +270,28 @@ ngx_http_perl_handle_request(ngx_http_re
 }
 
 
+static void
+ngx_http_perl_sleep_handler(ngx_http_request_t *r)
+{
+    ngx_event_t  *wev;
+
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "perl sleep handler");
+
+    wev = r->connection->write;
+
+    if (wev->timedout) {
+        wev->timedout = 0;
+        ngx_http_perl_handle_request(r);
+        return;
+    }
+
+    if (ngx_handle_write_event(wev, 0) == NGX_ERROR) {
+        ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+    }
+}
+
+
 static ngx_int_t
 ngx_http_perl_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
     uintptr_t data)
@@ -758,18 +786,6 @@ ngx_http_perl_cleanup_perl(void *data)
 #endif
 
 
-static void
-ngx_http_perl_cleanup_sv(void *data)
-{
-    ngx_http_perl_cleanup_t  *cln = data;
-
-    dTHXa(cln->perl);
-    PERL_SET_CONTEXT(cln->perl);
-
-    SvREFCNT_dec(cln->sv);
-}
-
-
 static ngx_int_t
 ngx_http_perl_preconfiguration(ngx_conf_t *cf)
 {
@@ -860,8 +876,6 @@ ngx_http_perl(ngx_conf_t *cf, ngx_comman
     ngx_http_perl_loc_conf_t *plcf = conf;
 
     ngx_str_t                  *value;
-    ngx_pool_cleanup_t         *cln;
-    ngx_http_perl_cleanup_t    *pcln;
     ngx_http_core_loc_conf_t   *clcf;
     ngx_http_perl_main_conf_t  *pmcf;
 
@@ -881,11 +895,6 @@ ngx_http_perl(ngx_conf_t *cf, ngx_comman
         }
     }
 
-    cln = ngx_pool_cleanup_add(cf->pool, sizeof(ngx_http_perl_cleanup_t));
-    if (cln == NULL) {
-        return NGX_CONF_ERROR;
-    }
-
     plcf->handler = value[1];
 
     {
@@ -907,11 +916,6 @@ ngx_http_perl(ngx_conf_t *cf, ngx_comman
 
     }
 
-    cln->handler = ngx_http_perl_cleanup_sv;
-    pcln = cln->data;
-    pcln->sv = plcf->sub;
-    pcln->perl = pmcf->perl;
-
     clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
     clcf->handler = ngx_http_perl_handler;
 
@@ -924,9 +928,7 @@ ngx_http_perl_set(ngx_conf_t *cf, ngx_co
 {
     ngx_int_t                   index;
     ngx_str_t                  *value;
-    ngx_pool_cleanup_t         *cln;
     ngx_http_variable_t        *v;
-    ngx_http_perl_cleanup_t    *pcln;
     ngx_http_perl_variable_t   *pv;
     ngx_http_perl_main_conf_t  *pmcf;
 
@@ -964,11 +966,6 @@ ngx_http_perl_set(ngx_conf_t *cf, ngx_co
         }
     }
 
-    cln = ngx_pool_cleanup_add(cf->pool, sizeof(ngx_http_perl_cleanup_t));
-    if (cln == NULL) {
-        return NGX_CONF_ERROR;
-    }
-
     pv->handler = value[2];
 
     {
@@ -990,11 +987,6 @@ ngx_http_perl_set(ngx_conf_t *cf, ngx_co
 
     }
 
-    cln->handler = ngx_http_perl_cleanup_sv;
-    pcln = cln->data;
-    pcln->sv = pv->sub;
-    pcln->perl = pmcf->perl;
-
     v->get_handler = ngx_http_perl_variable;
     v->data = (uintptr_t) pv;