Klaus Demo nginx / e773324
$r->sleep() Igor Sysoev 14 years ago
3 changed file(s) with 40 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
845845
846846
847847 void
848 sleep(r, sleep, next)
849 CODE:
850
851 dXSTARG;
852 ngx_http_request_t *r;
853 ngx_http_perl_ctx_t *ctx;
854
855 ngx_http_perl_set_request(r);
856
857 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
858
859 ctx->sleep = SvIV(ST(1));
860 ctx->next = SvRV(ST(2));
861
862 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
863 "perl sleep: %d", ctx->sleep);
864
865 XSRETURN_EMPTY;
866
867
868 void
848869 log_error(r, err, msg)
849870 CODE:
850871
4040 ngx_http_ssi_ctx_t *ssi_ctx, ngx_str_t **params);
4141 #endif
4242
43 static void ngx_http_perl_sleep_handler(ngx_http_request_t *r);
4344 static char *ngx_http_perl_init_interpreter(ngx_conf_t *cf,
4445 ngx_http_perl_main_conf_t *pmcf);
4546 static PerlInterpreter *
244245 ctx->filename.data = NULL;
245246 ctx->redirect_uri.len = 0;
246247
248 if (ctx->sleep) {
249 ngx_add_timer(r->connection->write, (ngx_msec_t) ctx->sleep);
250 r->write_event_handler = ngx_http_perl_sleep_handler;
251 ctx->sleep = 0;
252 }
253
247254 if (ctx->done || ctx->next) {
248255 return;
249256 }
259266 }
260267
261268 ngx_http_finalize_request(r, rc);
269 }
270
271
272 static void
273 ngx_http_perl_sleep_handler(ngx_http_request_t *r)
274 {
275 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
276 "perl sleep handler");
277
278 ngx_http_perl_handle_request(r);
262279 }
263280
264281
2222 ngx_str_t filename;
2323 ngx_str_t redirect_uri;
2424 ngx_str_t redirect_args;
25
2526 SV *next;
27 int sleep;
2628
2729 ngx_uint_t done; /* unsigned done:1; */
2830