xref: /unit/src/perl/nxt_perl_psgi_layer.c (revision 2060:a1991578c62e)
1510Salexander.borisov@nginx.com 
2510Salexander.borisov@nginx.com /*
3510Salexander.borisov@nginx.com  * Copyright (C) Alexander Borisov
4510Salexander.borisov@nginx.com  * Copyright (C) NGINX, Inc.
5510Salexander.borisov@nginx.com  */
6510Salexander.borisov@nginx.com 
7510Salexander.borisov@nginx.com #include <perl/nxt_perl_psgi_layer.h>
8510Salexander.borisov@nginx.com 
9510Salexander.borisov@nginx.com 
10510Salexander.borisov@nginx.com typedef struct {
11510Salexander.borisov@nginx.com     struct _PerlIO  base;
12510Salexander.borisov@nginx.com 
13510Salexander.borisov@nginx.com     SV              *var;
14510Salexander.borisov@nginx.com } nxt_perl_psgi_layer_stream_t;
15510Salexander.borisov@nginx.com 
16510Salexander.borisov@nginx.com 
17510Salexander.borisov@nginx.com static IV nxt_perl_psgi_layer_stream_pushed(pTHX_ PerlIO *f, const char *mode,
18510Salexander.borisov@nginx.com     SV *arg, PerlIO_funcs *tab);
19510Salexander.borisov@nginx.com static IV nxt_perl_psgi_layer_stream_popped(pTHX_ PerlIO *f);
20510Salexander.borisov@nginx.com 
21510Salexander.borisov@nginx.com static PerlIO *nxt_perl_psgi_layer_stream_open(pTHX_ PerlIO_funcs *self,
22510Salexander.borisov@nginx.com     PerlIO_list_t *layers, IV n,
23510Salexander.borisov@nginx.com     const char *mode, int fd, int imode, int perm,
24510Salexander.borisov@nginx.com     PerlIO *f, int narg, SV **args);
25510Salexander.borisov@nginx.com 
26510Salexander.borisov@nginx.com static IV nxt_perl_psgi_layer_stream_close(pTHX_ PerlIO *f);
27510Salexander.borisov@nginx.com 
28510Salexander.borisov@nginx.com static SSize_t nxt_perl_psgi_layer_stream_read(pTHX_ PerlIO *f,
29510Salexander.borisov@nginx.com     void *vbuf, Size_t count);
30510Salexander.borisov@nginx.com static SSize_t nxt_perl_psgi_layer_stream_write(pTHX_ PerlIO *f,
31510Salexander.borisov@nginx.com     const void *vbuf, Size_t count);
32510Salexander.borisov@nginx.com 
33510Salexander.borisov@nginx.com static IV nxt_perl_psgi_layer_stream_fileno(pTHX_ PerlIO *f);
34510Salexander.borisov@nginx.com static IV nxt_perl_psgi_layer_stream_seek(pTHX_ PerlIO *f,
35510Salexander.borisov@nginx.com     Off_t offset, int whence);
36510Salexander.borisov@nginx.com static Off_t nxt_perl_psgi_layer_stream_tell(pTHX_ PerlIO *f);
37510Salexander.borisov@nginx.com static IV nxt_perl_psgi_layer_stream_fill(pTHX_ PerlIO *f);
38510Salexander.borisov@nginx.com static IV nxt_perl_psgi_layer_stream_flush(pTHX_ PerlIO *f);
39510Salexander.borisov@nginx.com 
40510Salexander.borisov@nginx.com static SV *nxt_perl_psgi_layer_stream_arg(pTHX_ PerlIO *f,
41510Salexander.borisov@nginx.com     CLONE_PARAMS *param, int flags);
42510Salexander.borisov@nginx.com 
43510Salexander.borisov@nginx.com static PerlIO *nxt_perl_psgi_layer_stream_dup(pTHX_ PerlIO *f, PerlIO *o,
44510Salexander.borisov@nginx.com     CLONE_PARAMS *param, int flags);
45510Salexander.borisov@nginx.com static IV nxt_perl_psgi_layer_stream_eof(pTHX_ PerlIO *f);
46510Salexander.borisov@nginx.com 
47510Salexander.borisov@nginx.com static STDCHAR *nxt_perl_psgi_layer_stream_get_base(pTHX_ PerlIO *f);
48510Salexander.borisov@nginx.com static STDCHAR *nxt_perl_psgi_layer_stream_get_ptr(pTHX_ PerlIO *f);
49510Salexander.borisov@nginx.com static SSize_t nxt_perl_psgi_layer_stream_get_cnt(pTHX_ PerlIO *f);
50510Salexander.borisov@nginx.com static Size_t nxt_perl_psgi_layer_stream_buffersize(pTHX_ PerlIO *f);
51510Salexander.borisov@nginx.com static void nxt_perl_psgi_layer_stream_set_ptrcnt(pTHX_ PerlIO *f,
52510Salexander.borisov@nginx.com     STDCHAR *ptr, SSize_t cnt);
53510Salexander.borisov@nginx.com 
54510Salexander.borisov@nginx.com 
55510Salexander.borisov@nginx.com static PERLIO_FUNCS_DECL(PerlIO_NGINX_Unit) = {
56510Salexander.borisov@nginx.com     sizeof(PerlIO_funcs),
57510Salexander.borisov@nginx.com     "NGINX_Unit_PSGI_Layer_Stream",
58510Salexander.borisov@nginx.com     sizeof(nxt_perl_psgi_layer_stream_t),
59510Salexander.borisov@nginx.com     PERLIO_K_BUFFERED | PERLIO_K_RAW,
60510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_pushed,
61510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_popped,
62510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_open,
63510Salexander.borisov@nginx.com     PerlIOBase_binmode,
64510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_arg,
65510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_fileno,
66510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_dup,
67510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_read,
68510Salexander.borisov@nginx.com     NULL,
69510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_write,
70510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_seek,
71510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_tell,
72510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_close,
73510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_flush,
74510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_fill,
75510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_eof,
76510Salexander.borisov@nginx.com     PerlIOBase_error,
77510Salexander.borisov@nginx.com     PerlIOBase_clearerr,
78510Salexander.borisov@nginx.com     PerlIOBase_setlinebuf,
79510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_get_base,
80510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_buffersize,
81510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_get_ptr,
82510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_get_cnt,
83510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_set_ptrcnt,
84510Salexander.borisov@nginx.com };
85510Salexander.borisov@nginx.com 
86510Salexander.borisov@nginx.com 
87510Salexander.borisov@nginx.com static IV
nxt_perl_psgi_layer_stream_pushed(pTHX_ PerlIO * f,const char * mode,SV * arg,PerlIO_funcs * tab)88510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg,
89510Salexander.borisov@nginx.com     PerlIO_funcs *tab)
90510Salexander.borisov@nginx.com {
91510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_t  *unit_stream;
92510Salexander.borisov@nginx.com 
93510Salexander.borisov@nginx.com     unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
94510Salexander.borisov@nginx.com 
95510Salexander.borisov@nginx.com     if (arg != NULL && SvOK(arg)) {
96*2060Smax.romanov@nginx.com         unit_stream->var = SvREFCNT_inc(arg);
97510Salexander.borisov@nginx.com     }
98510Salexander.borisov@nginx.com 
99510Salexander.borisov@nginx.com     return PerlIOBase_pushed(aTHX_ f, mode, Nullsv, tab);
100510Salexander.borisov@nginx.com }
101510Salexander.borisov@nginx.com 
102510Salexander.borisov@nginx.com 
103510Salexander.borisov@nginx.com static IV
nxt_perl_psgi_layer_stream_popped(pTHX_ PerlIO * f)104510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_popped(pTHX_ PerlIO *f)
105510Salexander.borisov@nginx.com {
106*2060Smax.romanov@nginx.com     nxt_perl_psgi_io_arg_t        *arg;
107510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_t  *unit_stream;
108510Salexander.borisov@nginx.com 
109510Salexander.borisov@nginx.com     unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
110510Salexander.borisov@nginx.com 
111510Salexander.borisov@nginx.com     if (unit_stream->var != NULL) {
112*2060Smax.romanov@nginx.com         arg = (void *) (intptr_t) SvIV(SvRV(unit_stream->var));
113*2060Smax.romanov@nginx.com 
114*2060Smax.romanov@nginx.com         arg->io = NULL;
115*2060Smax.romanov@nginx.com         arg->fp = NULL;
116*2060Smax.romanov@nginx.com 
117510Salexander.borisov@nginx.com         SvREFCNT_dec(unit_stream->var);
118510Salexander.borisov@nginx.com         unit_stream->var = Nullsv;
119510Salexander.borisov@nginx.com     }
120510Salexander.borisov@nginx.com 
121510Salexander.borisov@nginx.com     return 0;
122510Salexander.borisov@nginx.com }
123510Salexander.borisov@nginx.com 
124510Salexander.borisov@nginx.com 
125510Salexander.borisov@nginx.com static PerlIO *
nxt_perl_psgi_layer_stream_open(pTHX_ PerlIO_funcs * self,PerlIO_list_t * layers,IV n,const char * mode,int fd,int imode,int perm,PerlIO * f,int narg,SV ** args)126510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_open(pTHX_ PerlIO_funcs *self,
127510Salexander.borisov@nginx.com     PerlIO_list_t *layers, IV n,
128510Salexander.borisov@nginx.com     const char *mode, int fd, int imode, int perm,
129510Salexander.borisov@nginx.com     PerlIO *f, int narg, SV **args)
130510Salexander.borisov@nginx.com {
131510Salexander.borisov@nginx.com     SV  *arg;
132510Salexander.borisov@nginx.com 
133510Salexander.borisov@nginx.com     arg = (narg > 0) ? *args : PerlIOArg;
134510Salexander.borisov@nginx.com 
135510Salexander.borisov@nginx.com     PERL_UNUSED_ARG(fd);
136510Salexander.borisov@nginx.com     PERL_UNUSED_ARG(imode);
137510Salexander.borisov@nginx.com     PERL_UNUSED_ARG(perm);
138510Salexander.borisov@nginx.com 
139510Salexander.borisov@nginx.com     if (SvROK(arg) || SvPOK(arg)) {
140510Salexander.borisov@nginx.com 
141510Salexander.borisov@nginx.com         if (f == NULL) {
142510Salexander.borisov@nginx.com             f = PerlIO_allocate(aTHX);
143510Salexander.borisov@nginx.com         }
144510Salexander.borisov@nginx.com 
145510Salexander.borisov@nginx.com         f = PerlIO_push(aTHX_ f, self, mode, arg);
146510Salexander.borisov@nginx.com 
147510Salexander.borisov@nginx.com         if (f != NULL) {
148510Salexander.borisov@nginx.com             PerlIOBase(f)->flags |= PERLIO_F_OPEN;
149510Salexander.borisov@nginx.com         }
150510Salexander.borisov@nginx.com 
151510Salexander.borisov@nginx.com         return f;
152510Salexander.borisov@nginx.com     }
153510Salexander.borisov@nginx.com 
154510Salexander.borisov@nginx.com     return NULL;
155510Salexander.borisov@nginx.com }
156510Salexander.borisov@nginx.com 
157510Salexander.borisov@nginx.com 
158510Salexander.borisov@nginx.com static IV
nxt_perl_psgi_layer_stream_close(pTHX_ PerlIO * f)159510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_close(pTHX_ PerlIO *f)
160510Salexander.borisov@nginx.com {
161510Salexander.borisov@nginx.com     IV  code;
162510Salexander.borisov@nginx.com 
163510Salexander.borisov@nginx.com     code = PerlIOBase_close(aTHX_ f);
164510Salexander.borisov@nginx.com     PerlIOBase(f)->flags &= ~(PERLIO_F_RDBUF | PERLIO_F_WRBUF);
165510Salexander.borisov@nginx.com 
166510Salexander.borisov@nginx.com     return code;
167510Salexander.borisov@nginx.com }
168510Salexander.borisov@nginx.com 
169510Salexander.borisov@nginx.com 
170510Salexander.borisov@nginx.com static IV
nxt_perl_psgi_layer_stream_fileno(pTHX_ PerlIO * f)171510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_fileno(pTHX_ PerlIO *f)
172510Salexander.borisov@nginx.com {
173510Salexander.borisov@nginx.com     PERL_UNUSED_ARG(f);
174510Salexander.borisov@nginx.com     return -1;
175510Salexander.borisov@nginx.com }
176510Salexander.borisov@nginx.com 
177510Salexander.borisov@nginx.com 
178510Salexander.borisov@nginx.com static SSize_t
nxt_perl_psgi_layer_stream_read(pTHX_ PerlIO * f,void * vbuf,Size_t count)179510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_read(pTHX_ PerlIO *f, void *vbuf, Size_t count)
180510Salexander.borisov@nginx.com {
181510Salexander.borisov@nginx.com     nxt_perl_psgi_io_arg_t        *arg;
182510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_t  *unit_stream;
183510Salexander.borisov@nginx.com 
184510Salexander.borisov@nginx.com     if (f == NULL) {
185510Salexander.borisov@nginx.com         return 0;
186510Salexander.borisov@nginx.com     }
187510Salexander.borisov@nginx.com 
188510Salexander.borisov@nginx.com     if ((PerlIOBase(f)->flags & PERLIO_F_CANREAD) == 0) {
189510Salexander.borisov@nginx.com         PerlIOBase(f)->flags |= PERLIO_F_ERROR;
190510Salexander.borisov@nginx.com 
191510Salexander.borisov@nginx.com         SETERRNO(EBADF, SS_IVCHAN);
192510Salexander.borisov@nginx.com 
193510Salexander.borisov@nginx.com         return 0;
194510Salexander.borisov@nginx.com     }
195510Salexander.borisov@nginx.com 
196*2060Smax.romanov@nginx.com     unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
197*2060Smax.romanov@nginx.com     arg = (void *) (intptr_t) SvIV(SvRV(unit_stream->var));
198*2060Smax.romanov@nginx.com 
199*2060Smax.romanov@nginx.com     return arg->io_tab->read(PERL_GET_CONTEXT, arg, vbuf, count);
200510Salexander.borisov@nginx.com }
201510Salexander.borisov@nginx.com 
202510Salexander.borisov@nginx.com 
203510Salexander.borisov@nginx.com static SSize_t
nxt_perl_psgi_layer_stream_write(pTHX_ PerlIO * f,const void * vbuf,Size_t count)204510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_write(pTHX_ PerlIO *f,
205510Salexander.borisov@nginx.com     const void *vbuf, Size_t count)
206510Salexander.borisov@nginx.com {
207510Salexander.borisov@nginx.com     nxt_perl_psgi_io_arg_t        *arg;
208510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_t  *unit_stream;
209510Salexander.borisov@nginx.com 
210510Salexander.borisov@nginx.com     if (PerlIOBase(f)->flags & PERLIO_F_CANWRITE) {
211510Salexander.borisov@nginx.com         unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
212*2060Smax.romanov@nginx.com         arg = (void *) (intptr_t) SvIV(SvRV(unit_stream->var));
213510Salexander.borisov@nginx.com 
214*2060Smax.romanov@nginx.com         return arg->io_tab->write(PERL_GET_CONTEXT, arg, vbuf, count);
215510Salexander.borisov@nginx.com     }
216510Salexander.borisov@nginx.com 
217510Salexander.borisov@nginx.com     return 0;
218510Salexander.borisov@nginx.com }
219510Salexander.borisov@nginx.com 
220510Salexander.borisov@nginx.com 
221510Salexander.borisov@nginx.com static IV
nxt_perl_psgi_layer_stream_seek(pTHX_ PerlIO * f,Off_t offset,int whence)222510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_seek(pTHX_ PerlIO *f, Off_t offset, int whence)
223510Salexander.borisov@nginx.com {
224510Salexander.borisov@nginx.com     PERL_UNUSED_ARG(f);
225510Salexander.borisov@nginx.com     return 0;
226510Salexander.borisov@nginx.com }
227510Salexander.borisov@nginx.com 
228510Salexander.borisov@nginx.com 
229510Salexander.borisov@nginx.com static Off_t
nxt_perl_psgi_layer_stream_tell(pTHX_ PerlIO * f)230510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_tell(pTHX_ PerlIO *f)
231510Salexander.borisov@nginx.com {
232510Salexander.borisov@nginx.com     PERL_UNUSED_ARG(f);
233510Salexander.borisov@nginx.com     return 0;
234510Salexander.borisov@nginx.com }
235510Salexander.borisov@nginx.com 
236510Salexander.borisov@nginx.com 
237510Salexander.borisov@nginx.com static IV
nxt_perl_psgi_layer_stream_fill(pTHX_ PerlIO * f)238510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_fill(pTHX_ PerlIO *f)
239510Salexander.borisov@nginx.com {
240510Salexander.borisov@nginx.com     PERL_UNUSED_ARG(f);
241510Salexander.borisov@nginx.com     return -1;
242510Salexander.borisov@nginx.com }
243510Salexander.borisov@nginx.com 
244510Salexander.borisov@nginx.com 
245510Salexander.borisov@nginx.com static IV
nxt_perl_psgi_layer_stream_flush(pTHX_ PerlIO * f)246510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_flush(pTHX_ PerlIO *f)
247510Salexander.borisov@nginx.com {
248*2060Smax.romanov@nginx.com     return 0;
249510Salexander.borisov@nginx.com }
250510Salexander.borisov@nginx.com 
251510Salexander.borisov@nginx.com 
252510Salexander.borisov@nginx.com static SV *
nxt_perl_psgi_layer_stream_arg(pTHX_ PerlIO * f,CLONE_PARAMS * param,int flags)253510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_arg(pTHX_ PerlIO * f,
254510Salexander.borisov@nginx.com     CLONE_PARAMS *param, int flags)
255510Salexander.borisov@nginx.com {
256510Salexander.borisov@nginx.com     SV                            *var;
257510Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_t  *unit_stream;
258510Salexander.borisov@nginx.com 
259510Salexander.borisov@nginx.com     unit_stream = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
260510Salexander.borisov@nginx.com     var = unit_stream->var;
261510Salexander.borisov@nginx.com 
262510Salexander.borisov@nginx.com     if (flags & PERLIO_DUP_CLONE) {
263510Salexander.borisov@nginx.com         var = PerlIO_sv_dup(aTHX_ var, param);
264510Salexander.borisov@nginx.com 
265510Salexander.borisov@nginx.com     } else if (flags & PERLIO_DUP_FD) {
266528Salexander.borisov@nginx.com         var = newSVsv(var);
267510Salexander.borisov@nginx.com 
268510Salexander.borisov@nginx.com     } else {
269510Salexander.borisov@nginx.com         var = SvREFCNT_inc(var);
270510Salexander.borisov@nginx.com     }
271510Salexander.borisov@nginx.com 
272510Salexander.borisov@nginx.com     return var;
273510Salexander.borisov@nginx.com }
274510Salexander.borisov@nginx.com 
275510Salexander.borisov@nginx.com 
276510Salexander.borisov@nginx.com static PerlIO *
nxt_perl_psgi_layer_stream_dup(pTHX_ PerlIO * f,PerlIO * o,CLONE_PARAMS * param,int flags)277510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_dup(pTHX_ PerlIO *f, PerlIO *o,
278510Salexander.borisov@nginx.com     CLONE_PARAMS *param, int flags)
279510Salexander.borisov@nginx.com {
280528Salexander.borisov@nginx.com     nxt_perl_psgi_layer_stream_t  *fs;
281510Salexander.borisov@nginx.com 
282510Salexander.borisov@nginx.com     f = PerlIOBase_dup(aTHX_ f, o, param, flags);
283510Salexander.borisov@nginx.com 
284510Salexander.borisov@nginx.com     if (f != NULL) {
285510Salexander.borisov@nginx.com         fs = PerlIOSelf(f, nxt_perl_psgi_layer_stream_t);
286510Salexander.borisov@nginx.com         fs->var = nxt_perl_psgi_layer_stream_arg(aTHX_ o, param, flags);
287510Salexander.borisov@nginx.com     }
288510Salexander.borisov@nginx.com 
289510Salexander.borisov@nginx.com     return f;
290510Salexander.borisov@nginx.com }
291510Salexander.borisov@nginx.com 
292510Salexander.borisov@nginx.com 
293510Salexander.borisov@nginx.com static IV
nxt_perl_psgi_layer_stream_eof(pTHX_ PerlIO * f)294510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_eof(pTHX_ PerlIO *f)
295510Salexander.borisov@nginx.com {
296510Salexander.borisov@nginx.com     return 1;
297510Salexander.borisov@nginx.com }
298510Salexander.borisov@nginx.com 
299510Salexander.borisov@nginx.com 
300510Salexander.borisov@nginx.com static STDCHAR *
nxt_perl_psgi_layer_stream_get_base(pTHX_ PerlIO * f)301510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_get_base(pTHX_ PerlIO *f)
302510Salexander.borisov@nginx.com {
303510Salexander.borisov@nginx.com     return (STDCHAR *) NULL;
304510Salexander.borisov@nginx.com }
305510Salexander.borisov@nginx.com 
306510Salexander.borisov@nginx.com 
307510Salexander.borisov@nginx.com static STDCHAR *
nxt_perl_psgi_layer_stream_get_ptr(pTHX_ PerlIO * f)308510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_get_ptr(pTHX_ PerlIO *f)
309510Salexander.borisov@nginx.com {
310510Salexander.borisov@nginx.com     return (STDCHAR *) NULL;
311510Salexander.borisov@nginx.com }
312510Salexander.borisov@nginx.com 
313510Salexander.borisov@nginx.com 
314510Salexander.borisov@nginx.com static SSize_t
nxt_perl_psgi_layer_stream_get_cnt(pTHX_ PerlIO * f)315510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_get_cnt(pTHX_ PerlIO *f)
316510Salexander.borisov@nginx.com {
317510Salexander.borisov@nginx.com     return 0;
318510Salexander.borisov@nginx.com }
319510Salexander.borisov@nginx.com 
320510Salexander.borisov@nginx.com 
321510Salexander.borisov@nginx.com static Size_t
nxt_perl_psgi_layer_stream_buffersize(pTHX_ PerlIO * f)322510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_buffersize(pTHX_ PerlIO *f)
323510Salexander.borisov@nginx.com {
324510Salexander.borisov@nginx.com     return 0;
325510Salexander.borisov@nginx.com }
326510Salexander.borisov@nginx.com 
327510Salexander.borisov@nginx.com 
328510Salexander.borisov@nginx.com static void
nxt_perl_psgi_layer_stream_set_ptrcnt(pTHX_ PerlIO * f,STDCHAR * ptr,SSize_t cnt)329510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_set_ptrcnt(pTHX_ PerlIO *f,
330510Salexander.borisov@nginx.com     STDCHAR *ptr, SSize_t cnt)
331510Salexander.borisov@nginx.com {
332510Salexander.borisov@nginx.com     /* Need some code. */
333510Salexander.borisov@nginx.com }
334510Salexander.borisov@nginx.com 
335510Salexander.borisov@nginx.com 
336510Salexander.borisov@nginx.com void
nxt_perl_psgi_layer_stream_init(pTHX)337510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_init(pTHX)
338510Salexander.borisov@nginx.com {
339510Salexander.borisov@nginx.com     PerlIO_define_layer(aTHX_ PERLIO_FUNCS_CAST(&PerlIO_NGINX_Unit));
340510Salexander.borisov@nginx.com }
341510Salexander.borisov@nginx.com 
342510Salexander.borisov@nginx.com 
343510Salexander.borisov@nginx.com PerlIO *
nxt_perl_psgi_layer_stream_fp_create(pTHX_ SV * arg_rv,const char * mode)344*2060Smax.romanov@nginx.com nxt_perl_psgi_layer_stream_fp_create(pTHX_ SV *arg_rv,
345510Salexander.borisov@nginx.com     const char *mode)
346510Salexander.borisov@nginx.com {
347*2060Smax.romanov@nginx.com     return PerlIO_openn(aTHX_ "NGINX_Unit_PSGI_Layer_Stream",
348*2060Smax.romanov@nginx.com                         mode, 0, 0, 0, NULL, 1, &arg_rv);
349510Salexander.borisov@nginx.com }
350510Salexander.borisov@nginx.com 
351510Salexander.borisov@nginx.com 
352510Salexander.borisov@nginx.com void
nxt_perl_psgi_layer_stream_fp_destroy(pTHX_ PerlIO * io)353510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_fp_destroy(pTHX_ PerlIO *io)
354510Salexander.borisov@nginx.com {
355510Salexander.borisov@nginx.com     PerlIO_close(io);
356510Salexander.borisov@nginx.com }
357510Salexander.borisov@nginx.com 
358510Salexander.borisov@nginx.com 
359510Salexander.borisov@nginx.com SV *
nxt_perl_psgi_layer_stream_io_create(pTHX_ PerlIO * fp)360510Salexander.borisov@nginx.com nxt_perl_psgi_layer_stream_io_create(pTHX_ PerlIO *fp)
361510Salexander.borisov@nginx.com {
362510Salexander.borisov@nginx.com     SV  *rvio;
363510Salexander.borisov@nginx.com     IO  *thatio;
364510Salexander.borisov@nginx.com 
365510Salexander.borisov@nginx.com     thatio = newIO();
366510Salexander.borisov@nginx.com 
367510Salexander.borisov@nginx.com     if (thatio == NULL) {
368510Salexander.borisov@nginx.com         return NULL;
369510Salexander.borisov@nginx.com     }
370510Salexander.borisov@nginx.com 
371510Salexander.borisov@nginx.com     IoOFP(thatio) = fp;
372510Salexander.borisov@nginx.com     IoIFP(thatio) = fp;
373510Salexander.borisov@nginx.com 
374510Salexander.borisov@nginx.com     rvio = newRV_noinc((SV *) thatio);
375510Salexander.borisov@nginx.com 
376510Salexander.borisov@nginx.com     if (rvio == NULL) {
377510Salexander.borisov@nginx.com         SvREFCNT_dec(thatio);
378510Salexander.borisov@nginx.com         return NULL;
379510Salexander.borisov@nginx.com     }
380510Salexander.borisov@nginx.com 
381510Salexander.borisov@nginx.com     return rvio;
382510Salexander.borisov@nginx.com }
383