Re: mod_perl, mod_gzip and connection->fileno

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

From: Dan Kubb
Subject: Re: mod_perl, mod_gzip and connection->fileno
Date: 20:05 on 24 Feb 2005
[...]

>  > =head1 Detecting a Client Abort
>  >
>  >  # IsClientConnected? Might already be disconnected for busy
>  >  # site, if a user hits stop/reload
>  >
>  >  my $conn = $r->connection;
>  >  my $is_connected = $conn->aborted ? 0 : 1;
>  >  if($is_connected) {
>  >      if (defined(my $fileno = $conn->fileno(0))) {
>  >          my $s = IO::Select->new($fileno);
>  >          $is_connected = $s->can_read(0) ? 0 : 1;
>  >      } else { $is_connected = 0 }
>  >  }
> 
> Is there any way in mp2 to detect aborted connections
> using a similar approach to the mp1 example above?

After a bit of testing I came up with the following
routine that allows me to detect aborted connections
in mp2:

   use Apache::Connection;
   use Apache::RequestRec;
   use APR::Const -compile => qw(APR::POLLIN APR::TIMEUP);
   use APR::Socket;

   # ...

   sub is_connected {
     my $r = shift;  # an Apache::RequestRec object

     my $c = $r->connection;

     return if $c->aborted;

     return $c->client_socket->poll($c->pool, 0, APR::POLLIN) == APR::TIMEUP;
   }

This is the first time I've used APR::Socket::pool(),
so if there's anything wrong with the code above
please let me know.

By the way, is there a "proper" way for an mp2
handler to deal with a user hitting the stop button?

In my PerlResponseHandler I check the routine above,
and return Apache::DONE if the user has disconnected,
which saves me the trouble of generating dynamic
content for no reason.  I'm just not sure if this is
the right way to do it; for example I wondered if
you need to notify Apache in some way of the
disconnection, and what sort of HTTP status code
should be set.

        -- 
        
Thanks,

Dan
___________________________________________________________

Dan Kubb                  Email: dan.kubb@xxxxxxxxxxx.xxx
President                 Phone: (604) 820-0212
Autopilot Marketing, Inc.   Web: http://www.onautopilot.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
Dan Kubb 20:05 on 24 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