mrakus has asked for the wisdom of the Perl Monks concerning the following question:
Thanks to you ,ikegami. I wrote C function my_print_c() with your help! But i understand that in this function we emulate perl "print". I glad to see that this C function is more fast that perl... but i think if we'll find method to output C char * to FastCGI stream it will be more faster.use strict; use IO::Handle; use CGI::Fast; use FCGI::ProcManager; use POSIX qw(setsid); use Inline (Config => DIRECTORY => '/tmp/Inline', ); use Inline 'C'; my $PROCESSES = 10; my $SOCKET = "localhost:8000"; &main; 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); $proc_manager->pm_manage(); while($request->Accept() >= 0){ $proc_manager->pm_pre_dispatch(); my $cgi = CGI::Fast->new(); print $out "Content-type: text/html\r\n\r\n"; my_print_c(); $proc_manager->pm_post_dispatch(); } FCGI::CloseSocket($socket); } __END__ __C__ void my_print_c() { char *text = "HELLO WORLD!"; GV* const gv = PL_defoutgv; IO* io; MAGIC* mg; int success; SV* sv; sv = sv_2mortal(newSVpv(text,0)); io = GvIO(gv); if (!io && GvEGV(gv)) { io = GvIO(GvEGV(gv)); if (!io) { return FALSE; } } mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar); dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(SvTIED_obj((SV*)io, mg)); XPUSHs(sv); PUTBACK; call_method("PRINT", G_SCALAR); SPAGAIN; success = 0 != POPi; PUTBACK; FREETMPS; LEAVE; return success; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inline C + IO::Handle
by ikegami (Patriarch) on Apr 15, 2009 at 13:53 UTC | |
by mrakus (Initiate) on Apr 15, 2009 at 14:01 UTC | |
by ikegami (Patriarch) on Apr 15, 2009 at 14:16 UTC | |
by mrakus (Initiate) on Apr 15, 2009 at 14:35 UTC | |
by gone2015 (Deacon) on Apr 15, 2009 at 18:00 UTC | |
by ikegami (Patriarch) on Apr 15, 2009 at 16:46 UTC | |
|
Re: Inline C + IO::Handle
by almut (Canon) on Apr 15, 2009 at 19:05 UTC | |
by ikegami (Patriarch) on Apr 15, 2009 at 19:57 UTC | |
by syphilis (Archbishop) on Apr 16, 2009 at 04:21 UTC | |
by mrakus (Initiate) on Apr 16, 2009 at 15:34 UTC | |
by ikegami (Patriarch) on Apr 17, 2009 at 00:28 UTC | |
by mrakus (Initiate) on Apr 17, 2009 at 08:33 UTC | |
by ikegami (Patriarch) on Apr 17, 2009 at 13:41 UTC | |
|