in reply to Configurable IO buffersize?

This *ought* to work , untested, but I just copy/pasted the relevant bits from PerlIOBuf_get_base :) Edit perl-5.15.1/dist/IO/IO.xs
void setbuf(handle, ...) OutputStream handle CODE: if (handle) #ifdef PERLIO_IS_STDIO { char *buf = items == 2 && SvPOK(ST(1)) ? sv_grow(ST(1), BUFSIZ) : 0; setbuf(handle, buf); } #else { /* not_here("IO::Handle::setbuf"); */ PerlIOBuf * const b = PerlIOSelf(f, PerlIOBuf); PERL_UNUSED_CONTEXT; if(items == 2 && SvPOK(ST(1)) ) { b->bufsiz = SvLEN(ST(1)); Newxz(b->buf, b->bufsiz , STDCHAR); } } #endif
The transformation to setvbuf would be similar, but, i'll let you work out the logic :)

Replies are listed 'Best First'.
Re^2: Configurable IO buffersize?
by BrowserUk (Patriarch) on Aug 02, 2011 at 02:43 UTC

    Thank you kind Sir.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Ok, now I've tested it, it works, the concept is proved, but there are some issues, like using :raw causes PerlIO to croak -- probably something about XS I'm doing wrong :)

      I used ->getbufsiz to test if ->setbuf had effect, because Devel::Peek/Data::Peek was no help with handles, and trying to parse perliol.h with Convert::Binary::C wasn't happening

      This definitely needs official support

      Cheers

        Some more testing, none of these behave like :raw, they seem to "work"
        Fudge( __FILE__ , ':raw:perlio:encoding(UTF-16LE):crlf', 6 ); Fudge( __FILE__ , ':raw:perlio:encoding(UTF-16LE):utf8', 6 ); Fudge( __FILE__ , ':raw:perlio', 7666 ); Fudge( __FILE__ , ':raw:win32', 6 ); Fudge( __FILE__ , ':win32', 6 );

        Though now its obvious that the :raw issue is probably pointer arithmetic related (and/or related to Chicanery Needed to Handle Unicode Text on Microsoft Windows)

        It remains, that setting a lower length than previous buffer length, doesn't change the length, only setting a higher one changes it

        I reiterate, this definitely needs official support :)

        here are some issues, like using :raw causes PerlIO to croak

        Doesn't :raw disable buffering?


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
      Bah, typo (f not handle), still untested :)
      void setbuf(handle, ...) OutputStream handle CODE: if (handle) #ifdef PERLIO_IS_STDIO { char *buf = items == 2 && SvPOK(ST(1)) ? sv_grow(ST(1), BUFSIZ) : 0; setbuf(handle, buf); } #else { /* not_here("IO::Handle::setbuf"); */ PerlIOBuf * const b = PerlIOSelf( handle, PerlIOBuf); PERL_UNUSED_CONTEXT; if(items == 2 && SvPOK(ST(1)) ) { b->bufsiz = SvLEN(ST(1)); Newxz(b->buf, b->bufsiz , STDCHAR); } } #endif