support IO object is perl async mode too

This commit is contained in:
Unbit
2013-12-07 09:52:51 +00:00
parent 441013b71b
commit d81330c514
+29 -29
View File
@@ -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)));
}