Changeset 5118b32 for perl


Ignore:
Timestamp:
Sep 12, 2009, 11:22:14 PM (12 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
7967433
Parents:
eea72a1
git-author:
Alejandro R. Sedeño <asedeno@mit.edu> (09/12/09 20:54:05)
git-committer:
Alejandro R. Sedeño <asedeno@mit.edu> (09/12/09 23:22:14)
Message:
Switch jabber keep-alive and auto-away to a timer.

Dropping the dependency on the mainloop hook in jabber.
Increasing the keep-alive / auto-away interval in jabber to 5 seconds.
File:
1 edited

Legend:

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

    r8362a48 r5118b32  
    7070        register_keybindings();
    7171        register_filters();
    72         $BarnOwl::Hooks::mainLoop->add("BarnOwl::Module::Jabber::onMainLoop");
    7372        $BarnOwl::Hooks::getBuddyList->add("BarnOwl::Module::Jabber::onGetBuddyList");
    7473        $BarnOwl::Hooks::getQuickstart->add("BarnOwl::Module::Jabber::onGetQuickstart");
     
    106105$BarnOwl::Hooks::startup->add("BarnOwl::Module::Jabber::onStart");
    107106
    108 sub onMainLoop {
    109     return if ( !$conn->connected() );
     107sub do_keep_alive_and_auto_away {
     108    if ( !$conn->connected() ) {
     109        # We don't need this timer any more.
     110        delete $vars{keepAliveTimer};
     111        return;
     112    }
    110113
    111114    $vars{status_changed} = 0;
     
    121124        $vars{status} = 'Auto away after '.$auto_away.' minute'.($auto_away == 1 ? '' : 's').' idle.';
    122125        $vars{status_changed} = 1;
    123     } elsif ($idletime == 0 && $vars{show} ne '') {
     126    } elsif ($idletime <= $vars{idletime} && $vars{show} ne '') {
    124127        $vars{show} = '';
    125128        $vars{status} = '';
    126129        $vars{status_changed} = 1;
    127130    }
     131    $vars{idletime} = $idletime;
    128132
    129133    foreach my $jid ( $conn->getJIDs() ) {
     
    134138            BarnOwl::error("Connection for $jid undefined -- error in reload?");
    135139        }
    136         # We keep this in the mainloop hook for keep-alives
    137         my $status = $client->Process(0);
     140        my $status = $client->Process(0); # keep-alive
    138141        if ( !defined($status) ) {
    139142            BarnOwl::error("Jabber account $jid disconnected!");
    140143            do_logout($jid);
     144            next;
    141145        }
    142146        if ($::shutdown) {
     
    450454                    $completion_jids{$buddy->GetJID()} = 1;
    451455                }
     456                $vars{idletime} |= BarnOwl::getidletime();
     457                unless (exists $vars{keepAliveTimer}) {
     458                    $vars{keepAliveTimer} = BarnOwl::Timer->new({
     459                        'after' => 5,
     460                        'interval' => 5,
     461                        'cb' => sub { BarnOwl::Module::Jabber::do_keep_alive_and_auto_away(@_) }
     462                                                                });
     463                }
    452464            }
    453465        }
Note: See TracChangeset for help on using the changeset viewer.