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

Don't use puts/fputs. clib doesn't know anything about Perl. Use the functions such as PerlIO_puts in the linked document instead.

Replies are listed 'Best First'.
Re^4: Inline C + IO::Handle
by mrakus (Initiate) on Apr 15, 2009 at 14:35 UTC
    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?