From: Dirk Koopman Date: Wed, 21 Dec 2011 22:25:16 +0000 (+0000) Subject: start of AnyEvent conversion X-Git-Tag: 1.56^0 X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=commitdiff_plain;h=d17f05b19fac36a0a8a2f828912a1a7ebefae79f;p=spider.git start of AnyEvent conversion --- diff --git a/cmd/shutdown.pl b/cmd/shutdown.pl index 30592ad0..cfed8d40 100644 --- a/cmd/shutdown.pl +++ b/cmd/shutdown.pl @@ -12,6 +12,6 @@ foreach $ref (DXChannel::get_all()) { } # give some time for the buffers to empty and then shutdown (see cluster.pl) -$main::decease = 25; +$main::decease->send; return (1); diff --git a/perl/Msg.pm b/perl/Msg.pm index d3817bed..5aebab65 100644 --- a/perl/Msg.pm +++ b/perl/Msg.pm @@ -14,7 +14,6 @@ use strict; use DXUtil; -use IO::Select; use DXDebug; use Timer; diff --git a/perl/cluster.pl b/perl/cluster.pl index 5c3f0fb9..2cf7173f 100755 --- a/perl/cluster.pl +++ b/perl/cluster.pl @@ -52,6 +52,8 @@ BEGIN { $systime = time; } +use AnyEvent; + use DXVars; use Msg; use IntMsg; @@ -273,7 +275,6 @@ sub cease foreach $dxchan (DXChannel::get_all_nodes) { $dxchan->disconnect(2) unless $dxchan == $main::me; } - Msg->event_loop(100, 0.01); # disconnect users foreach $dxchan (DXChannel::get_all_users) { @@ -288,7 +289,6 @@ sub cease UDPMsg::finish(); # end everything else - Msg->event_loop(100, 0.01); DXUser::finish(); DXDupe::finish(); @@ -342,6 +342,45 @@ sub AGWrestart AGWMsg::init(\&new_channel); } +sub idle_loop +{ + my $timenow = time; + + DXChannel::process(); + +# $DB::trace = 0; + + # do timed stuff, ongoing processing happens one a second + if ($timenow != $systime) { + reap() if $zombies; + $systime = $timenow; + my $days = int ($systime / 86400); + if ($systime_days != $days) { + $systime_days = $days; + $systime_daystart = $days * 86400; + } + IsoTime::update($systime); + DXCron::process(); # do cron jobs + DXCommandmode::process(); # process ongoing command mode stuff + DXXml::process(); + DXProt::process(); # process ongoing ak1a pcxx stuff + DXConnect::process(); + DXMsg::process(); + DXDb::process(); + DXUser::process(); + DXDupe::process(); + AGWMsg::process(); + BPQMsg::process(); + + if (defined &Local::process) { + eval { + Local::process(); # do any localised processing + }; + dbg("Local::process error $@") if $@; + } + } +} + ############################################################# # # The start of the main line of code @@ -444,9 +483,14 @@ UDPMsg::init(\&new_channel); # load bad words dbg("load badwords: " . (BadWords::load or "Ok")); +# create end condvar +$decease = AnyEvent->condvar; + # prime some signals +my ($sigint, $sigterm); unless ($DB::VERSION) { - $SIG{INT} = $SIG{TERM} = sub { $decease = 1 }; + $sigint = AnyEvent->signal(signal=>'INT', cb=> sub{$decease->send}); + $sigterm = AnyEvent->signal(signal=>'TERM', cb=> sub{$decease->send}); } unless ($is_win) { @@ -535,49 +579,13 @@ $script->run($main::me) if $script; #open(DB::OUT, "|tee /tmp/aa"); -for (;;) { -# $DB::trace = 1; +my $idle_loop = AnyEvent->idle(cb => &idle_loop); - Msg->event_loop(10, 0.010); - my $timenow = time; - - DXChannel::process(); -# $DB::trace = 0; +# main loop +$decease->recv; - # do timed stuff, ongoing processing happens one a second - if ($timenow != $systime) { - reap() if $zombies; - $systime = $timenow; - my $days = int ($systime / 86400); - if ($systime_days != $days) { - $systime_days = $days; - $systime_daystart = $days * 86400; - } - IsoTime::update($systime); - DXCron::process(); # do cron jobs - DXCommandmode::process(); # process ongoing command mode stuff - DXXml::process(); - DXProt::process(); # process ongoing ak1a pcxx stuff - DXConnect::process(); - DXMsg::process(); - DXDb::process(); - DXUser::process(); - DXDupe::process(); - AGWMsg::process(); - BPQMsg::process(); - - if (defined &Local::process) { - eval { - Local::process(); # do any localised processing - }; - dbg("Local::process error $@") if $@; - } - } - if ($decease) { - last if --$decease <= 0; - } -} +idle_loop() for (1..25); cease(0); exit(0);