Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
PerlMonks client sockets: INET vs. UNIX

by petr999 (Acolyte)
on Apr 13, 2011 at 13:21 UTC ( [id://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 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 = ( '', '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 = ( '', '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/ line 25 FCGI::Client::Connection::__ANON__('ALRM') called at [..]/FCGI +/Client/ line 92 eval {...} called at [..]/FCGI/Client/ 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/ line 113 FCGI::Client::Connection::_read_timeout('FCGI::Client::Connect +ion=HASH(0x28983aa0)', 'SCALAR(0x289eef84)', 8, 0) called at [..]/FCG +I/Client/ line 63 FCGI::Client::Connection::_read_record('FCGI::Client::Connecti +on=HASH(0x28983aa0)', 'FCGI::Client::Connection=HASH(0x28983aa0)') ca +lled at [..]/FCGI/Client/ line 37 FCGI::Client::Connection::_receive_response('FCGI::Client::Con +nection=HASH(0x28983aa0)', 'IO::Socket::UNIX=GLOB(0x2875d0ac)') calle +d at [..]/FCGI/Client/ line 28 FCGI::Client::Connection::request('FCGI::Client::Connection=HA +SH(0x28983aa0)', 'HASH(0x28796110)', '') called at 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.

Replies are listed 'Best First'.
Re: 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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-06-15 02:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.