I determined empirically that the file descriptor of the client socket is
always 0 in my environment. I assume this is only true for the Prefork MPM.
For the curious, the code I developed is for a Comet/pushlet type server.
Looks like this:
--- Handoff.pm ---
package Handoff;
use strict;
use warnings;
use Apache::RequestRec ();
use Apache::RequestIO ();
use Apache::Const -compile => qw(:common :conn_keepalive :http);
use File::FDpasser;
use POSIX;
# 1. subserver creates a named socket (/tmp/handoff) and listens on it
# 2. browser connects to apache (thus creating client-socket) makes a request
# 3. Apache looks at the request, and decides that it should go to
# mod_handoff
# 4. mod_handoff connects to the subserver using the /tmp/handoff and
# creates a pipe-type socket (ipc-pipe). It sends client-socket to
# the subserver over ipc-pipe, closes client-socket, sends the request
# over ipc-pipe, and then logs the result. Note that client-socket
# only is closed from apache... it's still open in the subserver.
#
# 5. The subserver reads the request on ipc-pipe, and responds over
# client-socket.
#
# 6. If mod_handoff cannot open the fs-based socket, then it returns an
# error code of some kind to the client.
sub handler {
my ($r) = @_;
my $fh = endp_connect("/tmp/handoff");
if (not $fh) {
$r->warn("could not connect to handoff endpoint");
return &Apache2::Const::HTTP_SERVICE_UNAVAILABLE;
}
# This only works with the preform MPM, I think.
my $client = 0;
my $rc = send_file($fh,$client);
# To prevent Apache from writing to the socket (which we have handed
# off to another process), replace the client socket with /dev/null
POSIX::dup2(POSIX::open("/dev/null", &POSIX::O_RDWR), $client);
# send the request to the subserver
print $fh $r->the_request."\r\n";
# send the headers too
$r->headers_in->do(sub { my ($k, $v)[EMAIL PROTECTED]; print $fh "$k:
$v\r\n"; } );
close $fh;
# do whatever we can to prevent apache from using the client socket again
$r->assbackwards(1);
$r->connection->keepalive(&Apache2::Const::CONN_CLOSE);
return &Apache2::Const::DONE;
}
1;
------
On Fri, 19 Jan 2007 10:34:25 +0100, Torsten Foertsch <[EMAIL PROTECTED]> wrote:
> On Friday 19 January 2007 08:01, Daniel Risacher wrote:
>> From within a mod_perl request handler, fileno(STDOUT) returns -1, which
> is
>> the same thing I got from $r->FILENO.
>>
>> Any other ideas?
>
> $r->connection->client_socket is an APR::Socket. It corresponds to an
> apr_socket_t in C. This structure contains on UNIX an element called
> socketdes. That is probably what you want. AFAIK there is currently no way
> to
> access that bit from Perl level. But it's not very complicated to add such
> an
> interface.
>
> Torsten