Changeset 5c6d661 for perl/modules


Ignore:
Timestamp:
Apr 3, 2011, 3:06:02 PM (11 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
5f3f1e4
Parents:
ab6d8f0
git-author:
Nelson Elhage <nelhage@mit.edu> (03/24/11 19:09:05)
git-committer:
Nelson Elhage <nelhage@mit.edu> (04/03/11 15:06:02)
Message:
IRC: Fix reconnect behavior.
Location:
perl/modules/IRC/lib/BarnOwl/Module
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/IRC/lib/BarnOwl/Module/IRC.pm

    rdace02a r5c6d661  
    394394    my $conn = shift;
    395395    if ($conn->conn->{socket}) {
     396        $conn->did_quit(1);
    396397        $conn->conn->disconnect("Goodbye!");
    397398    } elsif ($conn->{reconnect_timer}) {
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    rab6d8f0 r5c6d661  
    2121use base qw(Class::Accessor);
    2222use Exporter 'import';
    23 __PACKAGE__->mk_accessors(qw(conn alias motd names_tmp whois_tmp server autoconnect_channels));
     23__PACKAGE__->mk_accessors(qw(conn alias motd names_tmp whois_tmp
     24                             server autoconnect_channels
     25                             connect_args backoff did_quit));
    2426our @EXPORT_OK = qw(is_private);
    2527
     
    4244    $self->motd("");
    4345    $self->names_tmp(0);
     46    $self->backoff(0);
    4447    $self->whois_tmp("");
     48    $self->did_quit(0);
    4549
    4650    if(delete $args->{SSL}) {
    4751        $conn->enable_ssl;
    4852    }
     53    $self->connect_args([$host, $port, $args]);
    4954    $conn->connect($host, $port, $args);
    5055    $conn->{heap}{parent} = $self;
     
    9499                        nick_change   => on("nick"),
    95100                        ctcp_action   => on("ctcp_action"),
    96                         'irc_*' => sub { BarnOwl::debug("IRC: " . $_[1]->{command} .
     101                        'irc_*' => sub { BarnOwl::debug("IRC: " . $_[1]->{command} . " " .
    97102                                                        join(" ", @{$_[1]->{params}})) });
    98103
     
    244249sub disconnect {
    245250    my $self = shift;
    246     delete $BarnOwl::Module::IRC::ircnets{$self->alias};
    247     for my $k (keys %BarnOwl::Module::IRC::channels) {
    248         my @conns = grep {$_ ne $self} @{$BarnOwl::Module::IRC::channels{$k}};
    249         if(@conns) {
    250             $BarnOwl::Module::IRC::channels{$k} = \@conns;
    251         } else {
    252             delete $BarnOwl::Module::IRC::channels{$k};
    253         }
    254     }
    255     $self->motd("");
     251    $self->conn->disconnect;
    256252}
    257253
     
    259255    my ($self, $why) = @_;
    260256    BarnOwl::admin_message('IRC',
    261                            "[" . $self->alias . "] Disconnected from server");
    262     $self->disconnect;
    263     if ($why && $why =~ m{error in connection}) {
     257                           "[" . $self->alias . "] Disconnected from server: $why");
     258    $self->motd("");
     259    if (!$self->did_quit) {
    264260        $self->schedule_reconnect;
     261    } else {
     262        delete $BarnOwl::Module::IRC::ircnets{$self->alias};
    265263    }
    266264}
     
    400398sub schedule_reconnect {
    401399    my $self = shift;
    402     my $interval = shift || 5;
     400    my $interval = $self->backoff;
     401    if ($interval) {
     402        $interval *= 2;
     403        $interval = 60*5 if $interval > 60*5;
     404    } else {
     405        $interval = 5;
     406    }
     407    $self->backoff($interval);
    403408
    404409    my $weak = $self;
     
    443448    }
    444449    $self->conn->enable_ping(60, sub {
    445                                  $self->disconnect("Connection timed out.");
     450                                 $self->on_disconnect("Connection timed out.");
    446451                                 $self->schedule_reconnect;
    447452                             });
     453    $self->backoff(0);
    448454}
    449455
    450456sub reconnect {
    451457    my $self = shift;
    452     my $backoff = shift;
     458    my $backoff = $self->backoff;
    453459
    454460    $self->autoconnect_channels([keys(%{$self->{channel_list}})]);
    455     $self->conn->connect;
    456     if ($self->conn->connected) {
    457         $self->connected("Reconnected to ".$self->alias);
    458         return;
    459     }
    460 
    461     $backoff *= 2;
    462     $backoff = 60*5 if $backoff > 60*5;
    463     $self->schedule_reconnect( $backoff );
     461    $self->conn->connect(@{$self->connect_args});
    464462}
    465463
Note: See TracChangeset for help on using the changeset viewer.