Stas Bekman schrieb:

Marcel Greter wrote:

Stas Bekman schrieb:

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

It should do the same thing. IMHO IO::Select is just a frontend for the core select function, so you don't need to fiddle with vec yourself. One can save some memory (504 KB here) if you use the core select function directly and don't load IO::Select, which is always a good thing.


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

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




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 :-)

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?

Marcel



Reply via email to