From 99a1089384a04d960844a8fcfc0db5cbbb39e554 Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Thu, 10 Feb 2000 02:21:49 +0000 Subject: [PATCH] status() routine now tries upto 30 times to connect to spong-server --- src/lib/Spong/Status.pm | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/lib/Spong/Status.pm b/src/lib/Spong/Status.pm index f0822bd..fcb5d41 100755 --- a/src/lib/Spong/Status.pm +++ b/src/lib/Spong/Status.pm @@ -28,14 +28,22 @@ sub status { my( $addr, $host, $cat, $color, $summary, $message ) = @_; my( $sock, $ok ); - $sock = IO::Socket::INET->new( PeerAddr => $addr, - PeerPort => $main::SPONG_UPDATE_PORT, - Proto => 'tcp', - Timeout => 30, - Reuse => 1, - ); - - if ( ! defined $sock ) { + # Try 30 times to connect to spong-server + for ( 1..30 ) { + $sock = IO::Socket::INET->new( PeerAddr => $addr, + PeerPort => $main::SPONG_UPDATE_PORT, + Proto => 'tcp', + Timeout => 30, + Reuse => 1, + ); + + if ( defined $sock ) { # Once we got a connection, exit the loop + last; + } + sleep 1; # Pause a second to not overwhelm the network stack + } + + if (! defined $sock ) { croak "Could not connect with Spong Server: $@"; } -- 2.30.2