Hi, I am building a mod_perl PerlProcessConnectionHandler, and am using nonblocking sockets, for fine-grained error control.
My first question is regarding a bit of documentation ambiguity about the poll() method. 'perldoc APR::Socket' says that the timeout is milliseconds, but the example suggests that it is microseconds. My other question is about my usage of this method. Is it correct? It seems that every time I call $sock->poll(), it returns success, indicating that it's ok to write to the socket. But then, when I call $sock->send(), it barfs. For this test case, the client is purposely closing its socket early. Thanks for any help, -Colin. Code snippet: SENDING: while ( $sent < $total && ( $timeleft = $timeout - tv_interval( $starttime ) ) > 0 ) { log_stuff( "about to poll with timeleft [$timeleft]" ); my $rc = $sock->poll( $c->pool, int( $timeleft * 1_000_000 ), # timeleft is seconds APR::Const::POLLOUT ); log_stuff( "poll result: [$rc] [" . APR::Error::strerror( $rc ) . ']' ); if ( $rc == APR::Const::TIMEUP ) { $timeleft = -1; last SENDING; } unless ( $rc == APR::Const::SUCCESS ) { die "problem while waiting to send results to client: " . APR::Error::strerror( $rc ); } my $bytes = eval { $sock->send( substr( $return, $sent, $total ) ) }; if ( my $err = $@ ) { log_stuff( "error while sending return message: [$err]" ); } else { $sent += $bytes; log_stuff( "sent [$bytes] bytes of [$total] total to client: [$client_ip]" ); } } if ( $timeleft <= 0 ) { log_stuff( "timed out while sending response to client" ); } else { log_stuff( "sent results to client ip [$client_ip]" ); } Log snippet: 11:44:43: about to poll with timeleft [3.999991] 11:44:43: poll result: [0] [Success] 11:44:43: sent [65532] bytes of [199361] total to client: [127.0.0.1] 11:44:43: about to poll with timeleft [3.999343] 11:44:43: poll result: [0] [Success] 11:44:43: error while sending return message: [APR::Socket::send: (32) Broken pipe at /home/cmeyer ... line 91] 11:44:43: about to poll with timeleft [3.998755] 11:44:43: poll result: [0] [Success] 11:44:43: error while sending return message: [APR::Socket::send: (32) Broken pipe at /home/cmeyer ... line 91] # ... many more similar lines 11:44:47: about to poll with timeleft [0.000156000000000045] 11:44:47: poll result: [0] [Success] 11:44:47: error while sending return message: [APR::Socket::send: (32) Broken pipe at /home/cmeyer ... line 91] 11:44:47: timed out while sending response to client