The problem with FCGI is that it uses tied handles. As a quick check of the source reveals, it attaches "magic" to the filehandles in order to bind read/write calls, etc. to its own stream implementation (underneath PerlIO) — see NewStream() in fcgiapp.c, and FCGI_Bind() in FCGI.XL, if interested.

In other words, the simple approach specifying PerlIO * fh in combination with PerlIO_puts() doesn't work here, as it fails to resolve the associated magic.  For example, the following piece of code doesn't work for essentially the same reasons:

#!/usr/bin/perl use IO::Handle; use Inline (Config => DIRECTORY => '/tmp/Inline', ); use Inline 'C'; my $out = new IO::Handle(); tie *$out, "MyFH"; print $out "Content-type: text/html\r\n\r\n"; my_print($out); package MyFH; sub TIEHANDLE { my $class = shift; open my $fh, ">", "test.out" or die $!; bless $fh, $class; } sub PRINT { my $self = shift; print $self @_; } __END__ __C__ void my_print(PerlIO *fh) { PerlIO_puts(fh, "TEXT"); }

While the "Content-type..." line ends up in "test.out" as expected, the string "TEXT" does not.  OTOH, with a normal filehandle as $out, everything works fine (as already shown by oshalla).

Unfortunately, I don't have the time at the moment to work out the details of how to properly handle that magic on the XS side (tied filehandles are kinda special beasts, with hardly any documentation available besides the sources...) — in particular as this would entail not only figuring out how to do it in XS, but also how to then have Inline::C auto-generate the required code...

If someone else feels like tackling this, please go ahead, and let us know what you come up with :)


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.