Binary exponential backoff on IRC reconnect.
authorpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Tue, 21 Apr 2009 14:00:12 +0000 (14:00 +0000)
committerpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Tue, 21 Apr 2009 14:00:12 +0000 (14:00 +0000)
git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@90 088b83a4-0077-4247-935c-42ec02c2848b

irc.pl

diff --git a/irc.pl b/irc.pl
index ac8d92e..0d2e80e 100644 (file)
--- 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 );