checking for socket connected-ness on sysread
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Fri, 21 Apr 2006 02:41:01 +0000 (02:41 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Fri, 21 Apr 2006 02:41:01 +0000 (02:41 +0000)
inbound now re-connects on disconnect error

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@701 9efc2488-bf62-4759-914b-345cdb29e865

src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm
src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm

index 2ef75e6..eda6cf2 100644 (file)
@@ -258,9 +258,14 @@ sub timed_read {
                                }
 
                                my $t_buf = "";
-                               my $read_size = 1024;
-                               my $f = 0;
+                               my $read_size = 1024; my $f = 0;
                                while( my $n = sysread( $fh, $t_buf, $read_size ) ) {
+
+                                       unless( $fh->connected ) {
+                                               OpenSRF::EX::JabberDisconnected->throw(
+                                                       "Lost jabber client in timed_read()");
+                                       }
+
                                        $buffer .= $t_buf;
                                        if( $n < $read_size ) {
                                                #reset_fl( $fh, $f ) if $f;
index ad9a0d0..2bae137 100644 (file)
@@ -138,21 +138,29 @@ sub listen {
        
                        
        $logger->transport( $self->{app} . " going into listen loop", INFO );
+
        while(1) {
        
                my $sock = $self->unix_sock();
-               my $o = $self->process( -1 );
-
-               if( ! defined( $o ) ) {
-                       throw OpenSRF::EX::Jabber( "Listen Loop failed at 'process()'" );
+               my $o;
+
+               try {
+                       $o = $self->process( -1 );
+
+               } catch OpenSRF::EX::JabberDisconnected with {
+                       $logger->error("Inbound process lost its ".
+                               "jabber connection.  Attempting to reconnect...");
+                       $self->initialize;
+               };
+
+               if(defined $o) {
+                       my $socket = IO::Socket::UNIX->new( Peer => $sock  );
+                       throw OpenSRF::EX::Socket( "Unable to connect to UnixServer: socket-file: $sock \n :=> $! " )
+                               unless ($socket->connected);
+                       print $socket $o;
+                       $socket->close;
                }
 
-               my $socket = IO::Socket::UNIX->new( Peer => $sock  );
-               throw OpenSRF::EX::Socket( "Unable to connect to UnixServer: socket-file: $sock \n :=> $! " )
-                       unless ($socket->connected);
-               print $socket $o;
-               $socket->close;
-
        }
 
        throw OpenSRF::EX::Socket( "How did we get here?!?!" );