From 2c304ff86c6064f3ee761bd0013a4362462edd08 Mon Sep 17 00:00:00 2001 From: pdbogen Date: Tue, 21 Apr 2009 14:00:12 +0000 Subject: [PATCH] Binary exponential backoff on IRC reconnect. git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@90 088b83a4-0077-4247-935c-42ec02c2848b --- irc.pl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/irc.pl b/irc.pl index ac8d92e..0d2e80e 100644 --- a/irc.pl +++ b/irc.pl @@ -110,6 +110,7 @@ sub watchdog { my $self = $heap->{ "self" }; if( ! $heap->{ 'ircobject' }->connected() ) { print "IRC : Connection was lost.. reconnecting.\n"; + $heap->{ "watchdog" } *= 2; $kernel->post( $heap->{ 'ircobject' }->session_id(), "connect", { Nick => $self->{ "nick" }, Username => "Destult2", @@ -124,7 +125,7 @@ sub watchdog { if( $heap->{ 'timer' } == 60 ) { $kernel->post( $heap->{ 'ircobject' }->session_id(), "version" ); } - $kernel->delay_set( "watchdog", 5 ); + $kernel->delay_set( "watchdog", $heap->{ "watchdog" } ); } sub on_start { @@ -149,6 +150,7 @@ sub on_start { Server => $self->{ "host" }, Port => $self->{ "port" }, } ); + $heap->{ "watchdog" } = 5; $kernel->delay_set( "watchdog", 5 ); print( "IRC : Started.\n" ); } @@ -161,6 +163,7 @@ sub on_connect { print( "IRC : Attempting to register with nickserv.\n" ); $_[KERNEL]->post( $heap->{ 'ircobject' }->session_id(), "privmsg", "nickserv", "identify ".$self->{ "password" } ); } + $heap->{ "watchdog" } = 5; print( "IRC : Connected to irc://".$self->{ "host" }."/".$self->{ "channel" }."\n" ); for my $chan (split( /,/, $self->{ "channel" } )) { my @args = split( /:/, $chan ); -- 2.11.0