Re: mod_perl, mod_gzip and connection->fileno

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

From: Stas Bekman
Subject: Re: mod_perl, mod_gzip and connection->fileno
Date: 00:58 on 19 Feb 2005
Marcel Greter wrote:
> 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);

Is this better that IO::Select in [2]?

>    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.

Interesting.

But I guess this technique still want work in the proxied front-end <-> 
back-end setup, since the front end doesn't abort the connection to the 
back-end, even if the client did abort it.

> 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!?

Feel free to grab the source pod (right top corner of the page) and send 
the patch as you see it fit. You could also annotate the whole snippet 
while you are at it :) Thanks.

Also take a look at: 
http://perl.apache.org/docs/1.0/guide/debug.html#Handling_the__User_pressed_Stop_button__case
It's directly related and should probably be merged into one item. or at 
least xref each other.

> [1] http://perl.apache.org/docs/1.0/api/Apache.html#_c_E_gt_fileno____direction___ 
> 
> - 

[2] 
http://perl.apache.org/docs/1.0/guide/snippets.html#Detecting_a_Client_Abort




        -- 
        __________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@xxxxxx.xxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

(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