diff --git a/plugins/psgi/psgi_plugin.c b/plugins/psgi/psgi_plugin.c index 6b5a32ba..0cf2bd58 100644 --- a/plugins/psgi/psgi_plugin.c +++ b/plugins/psgi/psgi_plugin.c @@ -430,6 +430,7 @@ int uwsgi_perl_request(struct wsgi_request *wsgi_req) { struct uwsgi_app *wi = &uwsgi_apps[wsgi_req->app_id]; wi->requests++; + if (uwsgi.threads < 2) { if (((PerlInterpreter **)wi->interpreter)[0] != uperl.main[0]) { PERL_SET_CONTEXT(((PerlInterpreter **)wi->interpreter)[0]); @@ -447,6 +448,7 @@ int uwsgi_perl_request(struct wsgi_request *wsgi_req) { wsgi_req->async_environ = build_psgi_env(wsgi_req); if (!wsgi_req->async_environ) goto clear; + if (uwsgi.threads > 1) { wsgi_req->async_result = psgi_call(wsgi_req, ((SV **)wi->callable)[wsgi_req->async_id], wsgi_req->async_environ); } @@ -635,12 +637,12 @@ int uwsgi_perl_signal_handler(uint8_t sig, void *handler) { call_sv( SvRV((SV*)handler), G_DISCARD); + SPAGAIN; if(SvTRUE(ERRSV)) { uwsgi_log("[uwsgi-perl error] %s", SvPV_nolen(ERRSV)); ret = -1; } - SPAGAIN; PUTBACK; FREETMPS; LEAVE; @@ -653,17 +655,16 @@ void uwsgi_perl_run_hook(SV *hook) { ENTER; SAVETMPS; PUSHMARK(SP); - XPUSHs( hook ); PUTBACK; call_sv( SvRV(hook), G_DISCARD); + SPAGAIN; if(SvTRUE(ERRSV)) { uwsgi_log("[uwsgi-perl error] %s", SvPV_nolen(ERRSV)); return; } - SPAGAIN; PUTBACK; FREETMPS; LEAVE; diff --git a/plugins/psgi/psgi_response.c b/plugins/psgi/psgi_response.c index dfb79bc5..edfdb163 100644 --- a/plugins/psgi/psgi_response.c +++ b/plugins/psgi/psgi_response.c @@ -73,6 +73,7 @@ int psgi_response(struct wsgi_request *wsgi_req, AV *response) { char *status_str = SvPV(*status_code, hlen); if (uwsgi_response_prepare_headers(wsgi_req, status_str, hlen)) return UWSGI_OK; + hitem = av_fetch(response, 1, 0); if (!hitem) { uwsgi_log("invalid PSGI headers\n"); return UWSGI_OK;} @@ -86,6 +87,7 @@ int psgi_response(struct wsgi_request *wsgi_req, AV *response) { hitem = av_fetch(headers,i+1,0); chitem2 = SvPV(*hitem, hlen2); if (uwsgi_response_add_header(wsgi_req, chitem, hlen, chitem2, hlen2)) return UWSGI_OK; + i++; } hitem = av_fetch(response, 2, 0); diff --git a/test.psgi b/test.psgi index bbbf76ef..2d5a8e39 100644 --- a/test.psgi +++ b/test.psgi @@ -33,6 +33,15 @@ my $three = sub { print "three\n"; }; + +uwsgi::postfork(sub { + print "forked !!!\n"; +}); + +uwsgi::atexit(sub { + print "exited\n"; +}); + my $app = sub { my $env = shift; uwsgi::signal(17); @@ -55,11 +64,3 @@ my $app = sub { [ "Hello World\r\n", $env->{'REQUEST_URI'}, uwsgi::cache_get('key1'), uwsgi::call('hello') ], ]; }; - -uwsgi::postfork(sub { - print "forked !!!\n"; -}); - -uwsgi::atexit(sub { - print "exited\n"; -});