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