From d81330c514306ebc155044ffff0929eebd79d747 Mon Sep 17 00:00:00 2001 From: Unbit Date: Sat, 7 Dec 2013 09:52:51 +0000 Subject: [PATCH] support IO object is perl async mode too --- plugins/psgi/psgi_response.c | 58 ++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/plugins/psgi/psgi_response.c b/plugins/psgi/psgi_response.c index f91e47b4..e20cfc4d 100644 --- a/plugins/psgi/psgi_response.c +++ b/plugins/psgi/psgi_response.c @@ -100,41 +100,40 @@ int psgi_response(struct wsgi_request *wsgi_req, AV *response) { } if (!SvRV(*hitem)) { uwsgi_log("invalid PSGI response body\n") ; return UWSGI_OK; } - - if (SvROK(*hitem) && (SvTYPE(SvRV(*hitem)) == SVt_PVGV || SvTYPE(SvRV(*hitem)) == SVt_PVHV || SvTYPE(SvRV(*hitem)) == SVt_PVMG)) { - // respond to fileno ? - if (uwsgi.async < 2) { - // check for fileno() method, IO class or GvIO - if (uwsgi_perl_obj_can(*hitem, "fileno", 6) || uwsgi_perl_obj_isa(*hitem, "IO") || (uwsgi_perl_obj_isa(*hitem, "GLOB") && GvIO(SvRV(*hitem))) ) { - SV *fn = uwsgi_perl_obj_call(*hitem, "fileno"); - if (fn) { - if (SvTYPE(fn) == SVt_IV && SvIV(fn) >= 0) { - wsgi_req->sendfile_fd = SvIV(fn); - SvREFCNT_dec(fn); - uwsgi_response_sendfile_do(wsgi_req, wsgi_req->sendfile_fd, 0, 0); - // no need to close here as perl GC will do the close() - uwsgi_pl_check_write_errors { - // noop - } - return UWSGI_OK; - } + if (!SvROK(*hitem)) goto unsupported; + + if (SvTYPE(SvRV(*hitem)) == SVt_PVGV || SvTYPE(SvRV(*hitem)) == SVt_PVHV || SvTYPE(SvRV(*hitem)) == SVt_PVMG) { + + // check for fileno() method, IO class or GvIO + if (uwsgi_perl_obj_can(*hitem, "fileno", 6) || uwsgi_perl_obj_isa(*hitem, "IO") || (uwsgi_perl_obj_isa(*hitem, "GLOB") && GvIO(SvRV(*hitem))) ) { + SV *fn = uwsgi_perl_obj_call(*hitem, "fileno"); + if (fn) { + if (SvTYPE(fn) == SVt_IV && SvIV(fn) >= 0) { + wsgi_req->sendfile_fd = SvIV(fn); SvREFCNT_dec(fn); + uwsgi_response_sendfile_do(wsgi_req, wsgi_req->sendfile_fd, 0, 0); + // no need to close here as perl GC will do the close() + uwsgi_pl_check_write_errors { + // noop + } + return UWSGI_OK; } + SvREFCNT_dec(fn); } + } - // check for path method - if (uwsgi_perl_obj_can(*hitem, "path", 4)) { - SV *p = uwsgi_perl_obj_call(*hitem, "path"); - int fd = open(SvPV_nolen(p), O_RDONLY); - SvREFCNT_dec(p); - // the following function will close fd - uwsgi_response_sendfile_do(wsgi_req, fd, 0, 0); - uwsgi_pl_check_write_errors { - // noop - } - return UWSGI_OK; + // check for path method + if (uwsgi_perl_obj_can(*hitem, "path", 4)) { + SV *p = uwsgi_perl_obj_call(*hitem, "path"); + int fd = open(SvPV_nolen(p), O_RDONLY); + SvREFCNT_dec(p); + // the following function will close fd + uwsgi_response_sendfile_do(wsgi_req, fd, 0, 0); + uwsgi_pl_check_write_errors { + // noop } + return UWSGI_OK; } for(;;) { @@ -191,6 +190,7 @@ int psgi_response(struct wsgi_request *wsgi_req, AV *response) { } else { +unsupported: uwsgi_log("unsupported response body type: %d\n", SvTYPE(SvRV(*hitem))); }