Marcel Greter wrote:
[...]
How about we keep the original code using IO::Select and provide an example how to do it more efficiently? The IO::Select example is much more userfriendly :)

Maybe something like this? Don't know how much you want to annotate ??

I meant to explain what it does. Not everybody will understand how this code works by just reading it. And especially why you choose fd 0 and not fd 1.


=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 }
 }

You may also implement this without using the IO::Select module

 my $is_connected = 1;
 my $conn = $r->connection;
 # check Apache::Connection abort status
 if($conn->aborted) { $is_connected = 0 }
 else {
     if (defined(my $fileno = $conn->fileno(0))) {
         vec(my $rbit = '', $fileno, 1) = 1; # enable fd in vector table
         select($rbit, undef, undef, 0); # select for readable handles
         $is_connected = vec($rbit, $fileno, 1) ? 0 : 1; # check fd in
vector table
     } else { $is_connected = 0 }
 }

looks good.

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.

I'm checking the return value of each print, so this should take care of this case.



Wow! But most people don't. So in mp2 you no longer need to do that, as print() as well as all other IO methods croak on failure.


I'm doing a bigger framework, so there is actually just one place to
check the print function :-)

that's smart :)

So could you please adjust whatever needs to be adjusted in that section, and post here a patch to the POD source (or the section itself), while adding the discussion why one should use 0 and not 1, based on this thread?

Please see the addition above. I'll post a patch later, ss it might will
change. By 0/1, do you mean the fileno call?

Yup.


-- __________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com

Reply via email to