From 8a8c03f17454189a212ee74089fdbfd80d673d15 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 21 Apr 2006 02:41:01 +0000 Subject: [PATCH] checking for socket connected-ness on sysread inbound now re-connects on disconnect error git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@701 9efc2488-bf62-4759-914b-345cdb29e865 --- .../OpenSRF/Transport/SlimJabber/Client.pm | 9 +++++-- .../OpenSRF/Transport/SlimJabber/Inbound.pm | 28 ++++++++++++++-------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm b/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm index 2ef75e6..eda6cf2 100644 --- a/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm +++ b/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm @@ -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; diff --git a/src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm b/src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm index ad9a0d0..2bae137 100644 --- a/src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm +++ b/src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm @@ -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?!?!" ); -- 2.11.0