You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Paul Buder <pa...@aracnet.com> on 2001/01/10 01:17:00 UTC

STDIN, STDOUT, Socket::PassAccessRights problem

I am using a CPAN module called Socket::PassAccessRights
that uses the recvmsg and sendmsg system calls to pass
file descriptors over a socket.  More specifically, I have a
long living program (not modperl) that needs to communicate
with the Apache descriptors for STDIN and STDOUT given to a CGI
or modperl script.

The following works as an ordinary CGI but not under modperl.
use IO::Socket;
use Socket::PassAccessRights;

$client=IO::Socket::UNIX->new(Type => SOCK_STREAM,
Peer => '/tmp/socket') or die $!;

Socket::PassAccessRights::sendfd(fileno($client), fileno(STDIN)) or die;
Socket::PassAccessRights::sendfd(fileno($client), fileno(STDOUT)) or die;

# The only info my server needs from Apache other than
# the descriptors, this is POST'ed data.
print $client $ENV{CONTENT_LENGTH}, "\n";
# end of script

This doesn't work under modperl.  I suspect that is because
STDIN and STDOUT are not normal in some sense under modperl
but I don't know enough to get any handle on it.

You might wonder why I need modperl for such a tiny perl program.
The usual reason.  Even though it's so short the startup time as
an ordinary cgi is quite noticeably, irritatingly longer than the
corresponding C code I wrote.  But C limits my flexibility as I
would like to add a variety of things to the code above.

Any ideas?