perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Colin Meyer <cme...@helvella.org>
Subject Re: PerlProcessConnectionHandler and APR::Socket->poll()
Date Thu, 15 Feb 2007 16:25:39 GMT
On Wed, Feb 14, 2007 at 01:28:07PM -0800, Colin Meyer wrote:

[...]

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

Erm. I'm not sure why I was expecting ->poll() to block when the socket
was disconnected. Instead, I've added logic to try again or abort, based
on the error (if any) trapped from ->send().

-Colin.

> 
> 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]" );
-         }

+        if ( my $err = $@ ) {
+            if ( APR::Status::is_EAGAIN( $err ) ) {
+                log_stuff( "got EAGAIN on fileno [$sock->{fileno}]" ); 
+                next SENDING; 
+            }
+            else {
+                log_stuff( "error while sending return message: [$err]" );
+                $socket_error = 1;
+                last SENDING;
+            }
+        }


Mime
View raw message