perliol.pod
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· POD 代码 · 共 1,040 行 · 第 1/3 页
POD
1,040 行
Layer is line buffered. Write data should be passed to next layer downwhenever a "\n" is seen. Any data beyond the "\n" should then beprocessed.=item PERLIO_F_TEMPFile has been C<unlink()>ed, or should be deleted on C<close()>.=item PERLIO_F_OPENHandle is open.=item PERLIO_F_FASTGETSThis instance of this layer supports the "fast C<gets>" interface.Normally set based on C<PERLIO_K_FASTGETS> for the class and by theexistence of the function(s) in the table. However a class thatnormally provides that interface may need to avoid it on aparticular instance. The "pending" layer needs to do this whenit is pushed above a layer which does not support the interface.(Perl's C<sv_gets()> does not expect the streams fast C<gets> behaviourto change during one "get".)=back=head2 Methods in Detail=over 4=item fsize Size_t fsize;Size of the function table. This is compared against the value PerlIOcode "knows" as a compatibility check. Future versions I<may> be ableto tolerate layers compiled against an old version of the headers.=item name char * name;The name of the layer whose open() method Perl should invoke onopen(). For example if the layer is called APR, you will call: open $fh, ">:APR", ...and Perl knows that it has to invoke the PerlIOAPR_open() methodimplemented by the APR layer.=item size Size_t size;The size of the per-instance data structure, e.g.: sizeof(PerlIOAPR)If this field is zero then C<PerlIO_pushed> does not malloc anythingand assumes layer's Pushed function will do any required layer stackmanipulation - used to avoid malloc/free overhead for dummy layers.If the field is non-zero it must be at least the size of C<PerlIOl>,C<PerlIO_pushed> will allocate memory for the layer's data structuresand link new layer onto the stream's stack. (If the layer's Pushedmethod returns an error indication the layer is popped again.)=item kind IV kind;=over 4=item * PERLIO_K_BUFFEREDThe layer is buffered.=item * PERLIO_K_RAWThe layer is acceptable to have in a binmode(FH) stack - i.e. it does not(or will configure itself not to) transform bytes passing through it.=item * PERLIO_K_CANCRLFLayer can translate between "\n" and CRLF line ends.=item * PERLIO_K_FASTGETSLayer allows buffer snooping.=item * PERLIO_K_MULTIARGUsed when the layer's open() accepts more arguments than usual. Theextra arguments should come not before the C<MODE> argument. When thisflag is used it's up to the layer to validate the args.=back=item Pushed IV (*Pushed)(pTHX_ PerlIO *f,const char *mode, SV *arg);The only absolutely mandatory method. Called when the layer is pushedonto the stack. The C<mode> argument may be NULL if this occurspost-open. The C<arg> will be non-C<NULL> if an argument string waspassed. In most cases this should call C<PerlIOBase_pushed()> toconvert C<mode> into the appropriate C<PERLIO_F_XXXXX> flags inaddition to any actions the layer itself takes. If a layer is notexpecting an argument it need neither save the one passed to it, norprovide C<Getarg()> (it could perhaps C<Perl_warn> that the argumentwas un-expected).Returns 0 on success. On failure returns -1 and should set errno.=item Popped IV (*Popped)(pTHX_ PerlIO *f);Called when the layer is popped from the stack. A layer will normallybe popped after C<Close()> is called. But a layer can be poppedwithout being closed if the program is dynamically managing layers onthe stream. In such cases C<Popped()> should free any resources(buffers, translation tables, ...) not held directly in the layer'sstruct. It should also C<Unread()> any unconsumed data that has beenread and buffered from the layer below back to that layer, so that itcan be re-provided to what ever is now above.Returns 0 on success and failure. If C<Popped()> returns I<true> thenI<perlio.c> assumes that either the layer has popped itself, or thelayer is super special and needs to be retained for other reasons.In most cases it should return I<false>.=item Open PerlIO * (*Open)(...);The C<Open()> method has lots of arguments because it combines thefunctions of perl's C<open>, C<PerlIO_open>, perl's C<sysopen>,C<PerlIO_fdopen> and C<PerlIO_reopen>. The full prototype is asfollows: PerlIO * (*Open)(pTHX_ PerlIO_funcs *tab, AV *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *old, int narg, SV **args);Open should (perhaps indirectly) call C<PerlIO_allocate()> to allocatea slot in the table and associate it with the layers information forthe opened file, by calling C<PerlIO_push>. The I<layers> AV is anarray of all the layers destined for the C<PerlIO *>, and anyarguments passed to them, I<n> is the index into that array of thelayer being called. The macro C<PerlIOArg> will return a (possiblyC<NULL>) SV * for the argument passed to the layer.The I<mode> string is an "C<fopen()>-like" string which would matchthe regular expression C</^[I#]?[rwa]\+?[bt]?$/>.The C<'I'> prefix is used during creation of C<stdin>..C<stderr> viaspecial C<PerlIO_fdopen> calls; the C<'#'> prefix means that this isC<sysopen> and that I<imode> and I<perm> should be passed toC<PerlLIO_open3>; C<'r'> means B<r>ead, C<'w'> means B<w>rite andC<'a'> means B<a>ppend. The C<'+'> suffix means that both reading andwriting/appending are permitted. The C<'b'> suffix means file shouldbe binary, and C<'t'> means it is text. (Almost all layers should dothe IO in binary mode, and ignore the b/t bits. The C<:crlf> layershould be pushed to handle the distinction.)If I<old> is not C<NULL> then this is a C<PerlIO_reopen>. Perl itselfdoes not use this (yet?) and semantics are a little vague.If I<fd> not negative then it is the numeric file descriptor I<fd>,which will be open in a manner compatible with the supplied modestring, the call is thus equivalent to C<PerlIO_fdopen>. In this caseI<nargs> will be zero.If I<nargs> is greater than zero then it gives the number of argumentspassed to C<open>, otherwise it will be 1 if for exampleC<PerlIO_open> was called. In simple cases SvPV_nolen(*args) is thepathname to open.Having said all that translation-only layers do not need to provideC<Open()> at all, but rather leave the opening to a lower level layerand wait to be "pushed". If a layer does provide C<Open()> it shouldnormally call the C<Open()> method of next layer down (if any) andthen push itself on top if that succeeds.If C<PerlIO_push> was performed and open has failed, it mustC<PerlIO_pop> itself, since if it's not, the layer won't be removedand may cause bad problems.Returns C<NULL> on failure.=item Binmode IV (*Binmode)(pTHX_ PerlIO *f);Optional. Used when C<:raw> layer is pushed (explicitly or as a resultof binmode(FH)). If not present layer will be popped. If presentshould configure layer as binary (or pop itself) and return 0.If it returns -1 for error C<binmode> will fail with layerstill on the stack.=item Getarg SV * (*Getarg)(pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags);Optional. If present should return an SV * representing the stringargument passed to the layer when it waspushed. e.g. ":encoding(ascii)" would return an SvPV with value"ascii". (I<param> and I<flags> arguments can be ignored in mostcases)C<Dup> uses C<Getarg> to retrieve the argument originally passed toC<Pushed>, so you must implement this function if your layer has anextra argument to C<Pushed> and will ever be C<Dup>ed.=item Fileno IV (*Fileno)(pTHX_ PerlIO *f);Returns the Unix/Posix numeric file descriptor for the handle. NormallyC<PerlIOBase_fileno()> (which just asks next layer down) will sufficefor this.Returns -1 on error, which is considered to include the case where thelayer cannot provide such a file descriptor.=item Dup PerlIO * (*Dup)(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);XXX: Needs more docs.Used as part of the "clone" process when a thread is spawned (in whichcase param will be non-NULL) and when a stream is being duplicated via'&' in the C<open>.Similar to C<Open>, returns PerlIO* on success, C<NULL> on failure.=item Read SSize_t (*Read)(pTHX_ PerlIO *f, void *vbuf, Size_t count);Basic read operation.Typically will call C<Fill> and manipulate pointers (possibly via theAPI). C<PerlIOBuf_read()> may be suitable for derived classes whichprovide "fast gets" methods.Returns actual bytes read, or -1 on an error.=item Unread SSize_t (*Unread)(pTHX_ PerlIO *f, const void *vbuf, Size_t count);A superset of stdio's C<ungetc()>. Should arrange for future reads tosee the bytes in C<vbuf>. If there is no obviously better implementationthen C<PerlIOBase_unread()> provides the function by pushing a "fake""pending" layer above the calling layer.Returns the number of unread chars.=item Write SSize_t (*Write)(PerlIO *f, const void *vbuf, Size_t count);Basic write operation.Returns bytes written or -1 on an error.=item Seek IV (*Seek)(pTHX_ PerlIO *f, Off_t offset, int whence);Position the file pointer. Should normally call its own C<Flush>method and then the C<Seek> method of next layer down.Returns 0 on success, -1 on failure.=item Tell Off_t (*Tell)(pTHX_ PerlIO *f);Return the file pointer. May be based on layers cached concept ofposition to avoid overhead.Returns -1 on failure to get the file pointer.=item Close IV (*Close)(pTHX_ PerlIO *f);Close the stream. Should normally call C<PerlIOBase_close()> to flushitself and close layers below, and then deallocate any data structures(buffers, translation tables, ...) not held directly in the datastructure.Returns 0 on success, -1 on failure.=item Flush IV (*Flush)(pTHX_ PerlIO *f);Should make stream's state consistent with layers below. That is, anybuffered write data should be written, and file position of lower layersadjusted for data read from below but not actually consumed.(Should perhaps C<Unread()> such data to the lower layer.)Returns 0 on success, -1 on failure.=item Fill IV (*Fill)(pTHX_ PerlIO *f);The buffer for this layer should be filled (for read) from layerbelow. When you "subclass" PerlIOBuf layer, you want to use itsI<_read> method and to supply your own fill method, which fills thePerlIOBuf's buffer.Returns 0 on success, -1 on failure.=item Eof IV (*Eof)(pTHX_ PerlIO *f);Return end-of-file indicator. C<PerlIOBase_eof()> is normally sufficient.Returns 0 on end-of-file, 1 if not end-of-file, -1 on error.=item Error IV (*Error)(pTHX_ PerlIO *f);Return error indicator. C<PerlIOBase_error()> is normally sufficient.Returns 1 if there is an error (usually when C<PERLIO_F_ERROR> is set,0 otherwise.=item Clearerr void (*Clearerr)(pTHX_ PerlIO *f);Clear end-of-file and error indicators. Should call C<PerlIOBase_clearerr()>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?