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

I fixed the compilation errors. But like I said, it would make more sense to actually call print:
package MyModule; use Inline Config => ( DIRECTORY => './Inline', ); use Inline 'C'; sub _fprint { print { shift } @_ } # ... 1; __END__ __C__ int my_print(SV* fh, SV* sv) { int result; dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(fh); XPUSHs(sv); PUTBACK; call_pv("MyModule::_fprint", G_SCALAR); SPAGAIN; result = POPi; PUTBACK; FREETMPS; LEAVE; return result; }

Replies are listed 'Best First'.
Re^4: Inline C + IO::Handle
by mrakus (Initiate) on Apr 17, 2009 at 08:33 UTC
    > But like I said, it would make more sense to actually call print:

    I understand your idea, but i have to benchmark FastCGI perl output and C output. If i call perl "print" my idea is not working. I already benchmarked output large string to /dev/null and C code is more faster than perl. My idea compare FastCGI output, but i cant understand how to do it :)
      If you're interested in optimising and don't need a generic solution, then Re^2: Inline C + IO::Handle is going to be fastest. Replace MyFH with whichever namespace the FCGI handle is tied to. Magic is (relatively) slow, and this will avoid it completely.
        I try to do this, but C function dont print to stream :( Maybe i have mistake in code?
        sub main { my $proc_manager = new FCGI::ProcManager({ n_processes => $PRO +CESSES}); my $socket = FCGI::OpenSocket($SOCKET, 100); my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV +, $socket); my (undef, $out, undef) = $request->GetHandles(); $proc_manager->pm_manage(); while($request->Accept() >= 0){ $proc_manager->pm_pre_dispatch(); my $cgi = CGI::Fast->new(); print "Content-type: text/html\r\n\r\n"; my_print_c($out); $proc_manager->pm_post_dispatch(); } FCGI::CloseSocket($socket); } __END__ __C__ void my_print_c(SV * fh) { dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(fh)); XPUSHs(sv_2mortal(newSVpv("TEXT", 0))); PUTBACK; call_pv("PRINT", G_DISCARD); FREETMPS; LEAVE; }