mod_perl, mod_gzip and connection->fileno

[prev] [thread] [next] [Date index for 2005/02/18]

From: Marcel Greter
Subject: mod_perl, mod_gzip and connection->fileno
Date: 22:11 on 18 Feb 2005
I'm using a "check_connection" subroutine to check if a user has hit the 
stop button in his browser to abort the mod_perl handler. I actually 
found the solution for the problem while writing this email, but wanted 
to inform the list anyway, as the examples on the net all contain an 
error under this condition. For completeness, I also include the 
"check_connection" subroutine :

sub check_connection() {
    my $connection = Apache->request->connection;
    abort("connection aborted") if($connection->aborted);
    my $fileno = $connection->fileno(0);
    vec(my $rin = '', $fileno, 1) = 1;
    select(my $rout = $rin, undef, undef, 0);
    abort("connection aborted") if(vec($rout, $fileno, 1) eq 1);
return 1 }

The problem is that under mod_gzip, the output socket points to a 
"spool" file, used by mod_gzip. The examples on the net simply use 
$c->fileno, which will return the output file-descriptor (as written in 
the docs). When using mod_gzip, the check_function will not behave 
correctly. So for the "connection_check" function you must pass 0 to 
fileno to get the input file-descriptor.

Maybe someone could add a small note to the documentation, that for 
checking "disconnects" you need to check the input file-descriptor and 
not the output fd, as suggested by (nearly?) all examples. I'm not 100% 
sure if it makes any difference by using the input fd rather than the 
output fd, but under normal conditions they are both the same, right!?

- 
http://perl.apache.org/docs/1.0/api/Apache.html#_c_E_gt_fileno____direction___
- 
http://perl.apache.org/docs/1.0/guide/snippets.html#Detecting_a_Client_Abort

Greetings,
Marcel Greter

(message missing)

mod_perl, mod_gzip and connection->fileno
Marcel Greter 22:11 on 18 Feb 2005

Re: mod_perl, mod_gzip and connection->fileno
Stas Bekman 00:58 on 19 Feb 2005

Re: mod_perl, mod_gzip and connection->fileno
Marcel Greter 04:14 on 19 Feb 2005

Re: mod_perl, mod_gzip and connection->fileno
Stas Bekman 04:18 on 19 Feb 2005

Re: mod_perl, mod_gzip and connection->fileno
Marcel Greter 04:41 on 19 Feb 2005

Re: mod_perl, mod_gzip and connection->fileno
Stas Bekman 05:12 on 19 Feb 2005

Re: mod_perl, mod_gzip and connection->fileno
Geoffrey Young 20:13 on 24 Feb 2005

Re: mod_perl, mod_gzip and connection->fileno
Geoffrey Young 14:43 on 24 Feb 2005

Generated at 22:43 on 24 Feb 2005 by mariachi v0.52