diff options
author | Max Romanov <max.romanov@nginx.com> | 2021-12-27 16:37:35 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2021-12-27 16:37:35 +0300 |
commit | f8452838207d56892fb80b5976b37aab1efcaa1e (patch) | |
tree | 34ae7e0ab5df034c01377de108f9fc964e9d11d1 /src/perl/nxt_perl_psgi_layer.c | |
parent | 650784928293bb07b5b4acf4b14d3845b011556d (diff) | |
download | unit-f8452838207d56892fb80b5976b37aab1efcaa1e.tar.gz unit-f8452838207d56892fb80b5976b37aab1efcaa1e.tar.bz2 |
Perl: creating input and error streams if closed.
Application handler can do anything with a stream object (including close it).
Once the stream is closed, Unit creates a new stream.
This closes #616 issue on GitHub.
Diffstat (limited to 'src/perl/nxt_perl_psgi_layer.c')
-rw-r--r-- | src/perl/nxt_perl_psgi_layer.c | 64 |
1 files changed, 17 insertions, 47 deletions
diff --git a/src/perl/nxt_perl_psgi_layer.c b/src/perl/nxt_perl_psgi_layer.c index f77453e9..303e5f27 100644 --- a/src/perl/nxt_perl_psgi_layer.c +++ b/src/perl/nxt_perl_psgi_layer.c @@ -93,11 +93,9 @@ nxt_perl_psgi_layer_stream_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t); if (arg != NULL && SvOK(arg)) { - unit_stream->var = arg; + unit_stream->var = SvREFCNT_inc(arg); } - SvSETMAGIC(unit_stream->var); - return PerlIOBase_pushed(aTHX_ f, mode, Nullsv, tab); } @@ -105,11 +103,17 @@ nxt_perl_psgi_layer_stream_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, static IV nxt_perl_psgi_layer_stream_popped(pTHX_ PerlIO *f) { + nxt_perl_psgi_io_arg_t *arg; nxt_perl_psgi_layer_stream_t *unit_stream; unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t); if (unit_stream->var != NULL) { + arg = (void *) (intptr_t) SvIV(SvRV(unit_stream->var)); + + arg->io = NULL; + arg->fp = NULL; + SvREFCNT_dec(unit_stream->var); unit_stream->var = Nullsv; } @@ -181,9 +185,6 @@ nxt_perl_psgi_layer_stream_read(pTHX_ PerlIO *f, void *vbuf, Size_t count) return 0; } - unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t); - arg = (nxt_perl_psgi_io_arg_t *) (intptr_t) SvIV(SvRV(unit_stream->var)); - if ((PerlIOBase(f)->flags & PERLIO_F_CANREAD) == 0) { PerlIOBase(f)->flags |= PERLIO_F_ERROR; @@ -192,7 +193,10 @@ nxt_perl_psgi_layer_stream_read(pTHX_ PerlIO *f, void *vbuf, Size_t count) return 0; } - return (SSize_t) arg->read(PERL_GET_CONTEXT, arg, vbuf, count); + unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t); + arg = (void *) (intptr_t) SvIV(SvRV(unit_stream->var)); + + return arg->io_tab->read(PERL_GET_CONTEXT, arg, vbuf, count); } @@ -204,13 +208,10 @@ nxt_perl_psgi_layer_stream_write(pTHX_ PerlIO *f, nxt_perl_psgi_layer_stream_t *unit_stream; if (PerlIOBase(f)->flags & PERLIO_F_CANWRITE) { - unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t); + arg = (void *) (intptr_t) SvIV(SvRV(unit_stream->var)); - arg = (nxt_perl_psgi_io_arg_t *) - (intptr_t) SvIV(SvRV(unit_stream->var)); - - return (SSize_t) arg->write(PERL_GET_CONTEXT, arg, vbuf, count); + return arg->io_tab->write(PERL_GET_CONTEXT, arg, vbuf, count); } return 0; @@ -244,13 +245,7 @@ nxt_perl_psgi_layer_stream_fill(pTHX_ PerlIO *f) static IV nxt_perl_psgi_layer_stream_flush(pTHX_ PerlIO *f) { - nxt_perl_psgi_io_arg_t *arg; - nxt_perl_psgi_layer_stream_t *unit_stream; - - unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t); - arg = (nxt_perl_psgi_io_arg_t *) (intptr_t) SvIV(SvRV(unit_stream->var)); - - return (IV) arg->flush(PERL_GET_CONTEXT, arg); + return 0; } @@ -346,29 +341,11 @@ nxt_perl_psgi_layer_stream_init(pTHX) PerlIO * -nxt_perl_psgi_layer_stream_fp_create(pTHX_ nxt_perl_psgi_io_arg_t *arg, +nxt_perl_psgi_layer_stream_fp_create(pTHX_ SV *arg_rv, const char *mode) { - SV *arg_rv; - PerlIO *fp; - - arg_rv = newSV_type(SVt_RV); - - if (arg_rv == NULL) { - return NULL; - } - - sv_setptrref(arg_rv, arg); - - fp = PerlIO_openn(aTHX_ "NGINX_Unit_PSGI_Layer_Stream", - mode, 0, 0, 0, NULL, 1, &arg_rv); - - if (fp == NULL) { - SvREFCNT_dec(arg_rv); - return NULL; - } - - return fp; + return PerlIO_openn(aTHX_ "NGINX_Unit_PSGI_Layer_Stream", + mode, 0, 0, 0, NULL, 1, &arg_rv); } @@ -403,10 +380,3 @@ nxt_perl_psgi_layer_stream_io_create(pTHX_ PerlIO *fp) return rvio; } - - -void -nxt_perl_psgi_layer_stream_io_destroy(pTHX_ SV *rvio) -{ - SvREFCNT_dec(rvio); -} |