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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |