develooper Front page | perl.perl5.porters | Postings from December 2001

PerlIOBuf_fill "subclassing" question

From:
Stas Bekman
Date:
December 19, 2001 23:31
Subject:
PerlIOBuf_fill "subclassing" question
Message ID:
3C2193EA.3040104@stason.org
Since all the examples of _fill I have implement their own buffers I've 
no way to learn how to properly write my own _fill while using PerlIOBuf 
as a base. Here is what I've come up with, mostly by taking most of the 
stuff from PerlIOBuf itself. Did I lose things that I must have, or can 
I lose more things? Especially in the light of the FIXME notes in the 
PerlIOBUf. Thanks!

static IV PerlIOAPR_fill(pTHX_ PerlIO *f)
{
     PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR);
     apr_status_t rc;
     SSize_t avail;
     Size_t count = st->base.bufsiz;

     if (!st->base.buf)
	PerlIO_get_base(f);	/* allocate via vtable */

     rc = apr_file_read(st->file, st->base.ptr, &count);

     avail = count; /* read sets how many chars were read in count */
     if (avail <= 0) {
	if (avail == 0)
	    PerlIOBase(f)->flags |= PERLIO_F_EOF;
	else
	    PerlIOBase(f)->flags |= PERLIO_F_ERROR;
	return -1;
     }
     st->base.end = st->base.buf + avail;
     PerlIOBase(f)->flags |= PERLIO_F_RDBUF;
     return 0;
}

I use PerlIOBuf_read here:

static PerlIO_funcs PerlIO_APR = {
     "APR",
     sizeof(PerlIOAPR),
     PERLIO_K_BUFFERED | PERLIO_K_FASTGETS | PERLIO_K_MULTIARG,
     PerlIOBase_pushed,
     PerlIOAPR_popped,
     PerlIOAPR_open,
     NULL,  /* no getarg needed */
     PerlIOAPR_fileno,
     PerlIOAPR_dup,
     PerlIOBuf_read,
     PerlIOBuf_unread,
     PerlIOAPR_write,
     PerlIOAPR_seek,
     PerlIOAPR_tell,
     PerlIOAPR_close,
     PerlIOAPR_flush,
     PerlIOAPR_fill,
     PerlIOAPR_eof,
     PerlIOBase_error,
     PerlIOBase_clearerr,
     PerlIOBase_setlinebuf,
     PerlIOBuf_get_base,
     PerlIOBuf_bufsiz,
     PerlIOBuf_get_ptr,
     PerlIOBuf_get_cnt,
     PerlIOBuf_set_ptrcnt,
};

_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About