in reply to Re: Inline C + IO::Handle
in thread FCGI + Inline::C fast stream out!

I understand it but could you help me more? :) I try this:
... __END__ __C__ void my_print(FILE *f) { fputs("TEXT",f); }
But its not work too :( Do you have some simple code for me? :)

Replies are listed 'Best First'.
Re^3: Inline C + IO::Handle
by ikegami (Patriarch) on Apr 15, 2009 at 14:16 UTC
    Don't use puts/fputs. clib doesn't know anything about Perl. Use the functions such as PerlIO_puts in the linked document instead.
      Ok. I modified code like this:
      void my_print(PerlIO *f) { PerlIO_puts(f,"abcdef"); }
      but it still not work :( Perl "print $out 'TEXT';" work perfect but C "my_print" dot put chars to fastcgi stream. PerlIO_puts return -1 and errno set 9 (Bad file descriptor)

        I tried the following:

        use strict ; use warnings ; use Inline (Config => DIRECTORY => "$ENV{HOME}/PLIB/INLINE") ; use Inline 'C'; open my $fh, ">", "test.txt" ; my $rc = my_puts($fh) ; close $fh ; print "\$rc = $rc\n" ; __END__ __C__ int my_puts(PerlIO* fh) { return PerlIO_puts(fh, "Hello World !!\n") ; } ;
        and got the expected non-negative return code and the file test.txt ended up containing "Hello World !!\n"...

        ...I regret I cannot say why your attempt to output to a fastcgi stream is failing... but I can confirm that it is generally possible to use PerlIO "file handles", and output via the PerlIO_xxx API as suggested. It's worth noting that PerlIO_puts has arguments in the opposite order to fputs -- but looks pretty straightforward otherwise. I guess there could be something peculiar about the $out file handle you have... Wish I could help more.

        Sorry, I've never actually used this and I don't have time to learn it right now. Can anyone else help this monk?