nxt_perl_psgi_layer.c (528:5b2cb5212d75) nxt_perl_psgi_layer.c (2060:a1991578c62e)
1
2/*
3 * Copyright (C) Alexander Borisov
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <perl/nxt_perl_psgi_layer.h>
8

--- 79 unchanged lines hidden (view full) ---

88nxt_perl_psgi_layer_stream_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg,
89 PerlIO_funcs *tab)
90{
91 nxt_perl_psgi_layer_stream_t *unit_stream;
92
93 unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
94
95 if (arg != NULL && SvOK(arg)) {
1
2/*
3 * Copyright (C) Alexander Borisov
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <perl/nxt_perl_psgi_layer.h>
8

--- 79 unchanged lines hidden (view full) ---

88nxt_perl_psgi_layer_stream_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg,
89 PerlIO_funcs *tab)
90{
91 nxt_perl_psgi_layer_stream_t *unit_stream;
92
93 unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
94
95 if (arg != NULL && SvOK(arg)) {
96 unit_stream->var = arg;
96 unit_stream->var = SvREFCNT_inc(arg);
97 }
98
97 }
98
99 SvSETMAGIC(unit_stream->var);
100
101 return PerlIOBase_pushed(aTHX_ f, mode, Nullsv, tab);
102}
103
104
105static IV
106nxt_perl_psgi_layer_stream_popped(pTHX_ PerlIO *f)
107{
99 return PerlIOBase_pushed(aTHX_ f, mode, Nullsv, tab);
100}
101
102
103static IV
104nxt_perl_psgi_layer_stream_popped(pTHX_ PerlIO *f)
105{
106 nxt_perl_psgi_io_arg_t *arg;
108 nxt_perl_psgi_layer_stream_t *unit_stream;
109
110 unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
111
112 if (unit_stream->var != NULL) {
107 nxt_perl_psgi_layer_stream_t *unit_stream;
108
109 unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
110
111 if (unit_stream->var != NULL) {
112 arg = (void *) (intptr_t) SvIV(SvRV(unit_stream->var));
113
114 arg->io = NULL;
115 arg->fp = NULL;
116
113 SvREFCNT_dec(unit_stream->var);
114 unit_stream->var = Nullsv;
115 }
116
117 return 0;
118}
119
120

--- 55 unchanged lines hidden (view full) ---

176{
177 nxt_perl_psgi_io_arg_t *arg;
178 nxt_perl_psgi_layer_stream_t *unit_stream;
179
180 if (f == NULL) {
181 return 0;
182 }
183
117 SvREFCNT_dec(unit_stream->var);
118 unit_stream->var = Nullsv;
119 }
120
121 return 0;
122}
123
124

--- 55 unchanged lines hidden (view full) ---

180{
181 nxt_perl_psgi_io_arg_t *arg;
182 nxt_perl_psgi_layer_stream_t *unit_stream;
183
184 if (f == NULL) {
185 return 0;
186 }
187
184 unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
185 arg = (nxt_perl_psgi_io_arg_t *) (intptr_t) SvIV(SvRV(unit_stream->var));
186
187 if ((PerlIOBase(f)->flags & PERLIO_F_CANREAD) == 0) {
188 PerlIOBase(f)->flags |= PERLIO_F_ERROR;
189
190 SETERRNO(EBADF, SS_IVCHAN);
191
192 return 0;
193 }
194
188 if ((PerlIOBase(f)->flags & PERLIO_F_CANREAD) == 0) {
189 PerlIOBase(f)->flags |= PERLIO_F_ERROR;
190
191 SETERRNO(EBADF, SS_IVCHAN);
192
193 return 0;
194 }
195
195 return (SSize_t) arg->read(PERL_GET_CONTEXT, arg, vbuf, count);
196 unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
197 arg = (void *) (intptr_t) SvIV(SvRV(unit_stream->var));
198
199 return arg->io_tab->read(PERL_GET_CONTEXT, arg, vbuf, count);
196}
197
198
199static SSize_t
200nxt_perl_psgi_layer_stream_write(pTHX_ PerlIO *f,
201 const void *vbuf, Size_t count)
202{
203 nxt_perl_psgi_io_arg_t *arg;
204 nxt_perl_psgi_layer_stream_t *unit_stream;
205
206 if (PerlIOBase(f)->flags & PERLIO_F_CANWRITE) {
200}
201
202
203static SSize_t
204nxt_perl_psgi_layer_stream_write(pTHX_ PerlIO *f,
205 const void *vbuf, Size_t count)
206{
207 nxt_perl_psgi_io_arg_t *arg;
208 nxt_perl_psgi_layer_stream_t *unit_stream;
209
210 if (PerlIOBase(f)->flags & PERLIO_F_CANWRITE) {
207
208 unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
211 unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
212 arg = (void *) (intptr_t) SvIV(SvRV(unit_stream->var));
209
213
210 arg = (nxt_perl_psgi_io_arg_t *)
211 (intptr_t) SvIV(SvRV(unit_stream->var));
212
213 return (SSize_t) arg->write(PERL_GET_CONTEXT, arg, vbuf, count);
214 return arg->io_tab->write(PERL_GET_CONTEXT, arg, vbuf, count);
214 }
215
216 return 0;
217}
218
219
220static IV
221nxt_perl_psgi_layer_stream_seek(pTHX_ PerlIO *f, Off_t offset, int whence)

--- 17 unchanged lines hidden (view full) ---

239 PERL_UNUSED_ARG(f);
240 return -1;
241}
242
243
244static IV
245nxt_perl_psgi_layer_stream_flush(pTHX_ PerlIO *f)
246{
215 }
216
217 return 0;
218}
219
220
221static IV
222nxt_perl_psgi_layer_stream_seek(pTHX_ PerlIO *f, Off_t offset, int whence)

--- 17 unchanged lines hidden (view full) ---

240 PERL_UNUSED_ARG(f);
241 return -1;
242}
243
244
245static IV
246nxt_perl_psgi_layer_stream_flush(pTHX_ PerlIO *f)
247{
247 nxt_perl_psgi_io_arg_t *arg;
248 nxt_perl_psgi_layer_stream_t *unit_stream;
249
250 unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
251 arg = (nxt_perl_psgi_io_arg_t *) (intptr_t) SvIV(SvRV(unit_stream->var));
252
253 return (IV) arg->flush(PERL_GET_CONTEXT, arg);
248 return 0;
254}
255
256
257static SV *
258nxt_perl_psgi_layer_stream_arg(pTHX_ PerlIO * f,
259 CLONE_PARAMS *param, int flags)
260{
261 SV *var;

--- 79 unchanged lines hidden (view full) ---

341void
342nxt_perl_psgi_layer_stream_init(pTHX)
343{
344 PerlIO_define_layer(aTHX_ PERLIO_FUNCS_CAST(&PerlIO_NGINX_Unit));
345}
346
347
348PerlIO *
249}
250
251
252static SV *
253nxt_perl_psgi_layer_stream_arg(pTHX_ PerlIO * f,
254 CLONE_PARAMS *param, int flags)
255{
256 SV *var;

--- 79 unchanged lines hidden (view full) ---

336void
337nxt_perl_psgi_layer_stream_init(pTHX)
338{
339 PerlIO_define_layer(aTHX_ PERLIO_FUNCS_CAST(&PerlIO_NGINX_Unit));
340}
341
342
343PerlIO *
349nxt_perl_psgi_layer_stream_fp_create(pTHX_ nxt_perl_psgi_io_arg_t *arg,
344nxt_perl_psgi_layer_stream_fp_create(pTHX_ SV *arg_rv,
350 const char *mode)
351{
345 const char *mode)
346{
352 SV *arg_rv;
353 PerlIO *fp;
354
355 arg_rv = newSV_type(SVt_RV);
356
357 if (arg_rv == NULL) {
358 return NULL;
359 }
360
361 sv_setptrref(arg_rv, arg);
362
363 fp = PerlIO_openn(aTHX_ "NGINX_Unit_PSGI_Layer_Stream",
364 mode, 0, 0, 0, NULL, 1, &arg_rv);
365
366 if (fp == NULL) {
367 SvREFCNT_dec(arg_rv);
368 return NULL;
369 }
370
371 return fp;
347 return PerlIO_openn(aTHX_ "NGINX_Unit_PSGI_Layer_Stream",
348 mode, 0, 0, 0, NULL, 1, &arg_rv);
372}
373
374
375void
376nxt_perl_psgi_layer_stream_fp_destroy(pTHX_ PerlIO *io)
377{
378 PerlIO_close(io);
379}

--- 18 unchanged lines hidden (view full) ---

398
399 if (rvio == NULL) {
400 SvREFCNT_dec(thatio);
401 return NULL;
402 }
403
404 return rvio;
405}
349}
350
351
352void
353nxt_perl_psgi_layer_stream_fp_destroy(pTHX_ PerlIO *io)
354{
355 PerlIO_close(io);
356}

--- 18 unchanged lines hidden (view full) ---

375
376 if (rvio == NULL) {
377 SvREFCNT_dec(thatio);
378 return NULL;
379 }
380
381 return rvio;
382}
406
407
408void
409nxt_perl_psgi_layer_stream_io_destroy(pTHX_ SV *rvio)
410{
411 SvREFCNT_dec(rvio);
412}