diff options
author | Igor Sysoev <igor@sysoev.ru> | 2006-12-12 20:59:24 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2006-12-12 20:59:24 +0000 |
commit | e773324c3013cd9c0336db2f346f760d6c3a95cb (patch) | |
tree | df2f5e4ff22abda424870184103f0e8e74588d6e /src | |
parent | 332efbc4122d5028b6e61b15c155d477a29c8622 (diff) | |
download | nginx-e773324c3013cd9c0336db2f346f760d6c3a95cb.tar.gz nginx-e773324c3013cd9c0336db2f346f760d6c3a95cb.zip |
$r->sleep()
Diffstat (limited to 'src')
-rw-r--r-- | src/http/modules/perl/nginx.xs | 21 | ||||
-rw-r--r-- | src/http/modules/perl/ngx_http_perl_module.c | 17 | ||||
-rw-r--r-- | src/http/modules/perl/ngx_http_perl_module.h | 2 |
3 files changed, 40 insertions, 0 deletions
diff --git a/src/http/modules/perl/nginx.xs b/src/http/modules/perl/nginx.xs index a32c85e73..734f7bac8 100644 --- a/src/http/modules/perl/nginx.xs +++ b/src/http/modules/perl/nginx.xs @@ -846,6 +846,27 @@ variable(r, name, value = NULL) void +sleep(r, sleep, next) + CODE: + + dXSTARG; + ngx_http_request_t *r; + 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)); + + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "perl sleep: %d", ctx->sleep); + + XSRETURN_EMPTY; + + +void log_error(r, err, msg) CODE: diff --git a/src/http/modules/perl/ngx_http_perl_module.c b/src/http/modules/perl/ngx_http_perl_module.c index 1910a1bc9..94ff54f80 100644 --- 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_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 * @@ -245,6 +246,12 @@ 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; } @@ -263,6 +270,16 @@ ngx_http_perl_handle_request(ngx_http_request_t *r) } +static void +ngx_http_perl_sleep_handler(ngx_http_request_t *r) +{ + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "perl sleep handler"); + + ngx_http_perl_handle_request(r); +} + + static ngx_int_t ngx_http_perl_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data) diff --git a/src/http/modules/perl/ngx_http_perl_module.h b/src/http/modules/perl/ngx_http_perl_module.h index af23f9ef7..59954224d 100644 --- a/src/http/modules/perl/ngx_http_perl_module.h +++ b/src/http/modules/perl/ngx_http_perl_module.h @@ -23,7 +23,9 @@ typedef struct { ngx_str_t filename; ngx_str_t redirect_uri; ngx_str_t redirect_args; + SV *next; + int sleep; ngx_uint_t done; /* unsigned done:1; */ |