Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

FCGI.pm client sockets: INET vs. UNIX

by petr999 (Acolyte)
on Apr 13, 2011 at 13:21 UTC ( #899187=perlquestion: print w/ replies, xml ) Need Help??
petr999 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Friends,

I observe the difference in FCGI.pm usage.

When $f in the code is INET the client asks server and exits fine. Client code:

use FCGI; use IO::Socket; my $f = 'INET'; my @tcp = ( '127.0.0.1', '8888' ); my $lsock = "/tmp/spawn.sck"; my $s; if( $f eq 'UNIX' ){ ( -S $lsock ) and ( unlink( $lsock ) or die $! ); $s = FCGI::OpenSocket( $lsock, 5 ); } else { $s = FCGI::OpenSocket( join( ':', @tcp ), 5 ); } $s or die $!; my $r = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%ENV, $s ); while($r->Accept() >= 0) { print "Content-type: text/html\r\n\r\n"; }

Server code:

use IO::Socket; use FCGI::Client; my $f = 'INET'; my @tcp = ( '127.0.0.1', '8888' ); my $lsock = "/tmp/spawn.sck"; my $s = $f eq 'UNIX' ? IO::Socket::UNIX->new( "PeerAddr" => $lsock, "Type" => SOCK_STREAM +, Timeout => 3, ) : IO::Socket::INET->new( "PeerAddr" => $tcp[ 0 ], "PeerPort" => $tc +p[ 1 ], "Type" => SOCK_STREAM, Timeout => 3, ) ; $s or die $!; my $c = FCGI::Client::Connection -> new( sock => $s, timeout => 3, ); $c -> request( +{ REQUEST_METHOD => "GET", }, "" ); $s -> close;
But when $f is UNIX, it exits while trying to read from FCGI socket:
REQUEST_TIME_OUT at [.]/FCGI/Client/Connection.pm line 25 FCGI::Client::Connection::__ANON__('ALRM') called at [..]/FCGI +/Client/Connection.pm line 92 eval {...} called at [..]/FCGI/Client/Connection.pm line 92 FCGI::Client::Connection::_wait_socket('FCGI::Client::Connecti +on=HASH(0x28983aa0)', 'IO::Socket::UNIX=GLOB(0x2875d0ac)', undef, 130 +2700410.97483) called at [..]/FCGI/Client/Connection.pm line 113 FCGI::Client::Connection::_read_timeout('FCGI::Client::Connect +ion=HASH(0x28983aa0)', 'SCALAR(0x289eef84)', 8, 0) called at [..]/FCG +I/Client/Connection.pm line 63 FCGI::Client::Connection::_read_record('FCGI::Client::Connecti +on=HASH(0x28983aa0)', 'FCGI::Client::Connection=HASH(0x28983aa0)') ca +lled at [..]/FCGI/Client/Connection.pm line 37 FCGI::Client::Connection::_receive_response('FCGI::Client::Con +nection=HASH(0x28983aa0)', 'IO::Socket::UNIX=GLOB(0x2875d0ac)') calle +d at [..]/FCGI/Client/Connection.pm line 28 FCGI::Client::Connection::request('FCGI::Client::Connection=HA +SH(0x28983aa0)', 'HASH(0x28796110)', '') called at client00.pl line 1 +8

What can influence on that behavior? system is freebsd7.

Do I need to send a terminator character/sequence to end my FCGI request?

Or what should I do next? Make FCGI request manually and send it? I believe I can do with Net::FastCGI but I need to look at fastcgi spec for this...

Should this be a FCGI::Client bug?

Thank you.

Comment on FCGI.pm client sockets: INET vs. UNIX
Select or Download Code
Re: FCGI.pm client sockets: INET vs. UNIX
by fidesachates (Monk) on Apr 13, 2011 at 16:32 UTC
    Sorry to say I can't help you with the perl module, but I have a suggestion for testing. When dealing with sockets, you can use netcat to test your code. Netcat can act as client or server and gives you more finite control over what's being sent without modifying code.

      sniffing and interpreting means same bit-hacking to me as fastcgi specification digging.

      Thanks anyway, I had no idea about netcat is able to handle the local unix sockets.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://899187]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (16)
As of 2014-07-25 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (172 votes), past polls