]> dxcluster.net Git - spider.git/commitdiff
start of AnyEvent conversion 1.56
authorDirk Koopman <djk@tobit.co.uk>
Wed, 21 Dec 2011 22:25:16 +0000 (22:25 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Wed, 21 Dec 2011 22:25:16 +0000 (22:25 +0000)
cmd/shutdown.pl
perl/Msg.pm
perl/cluster.pl

index 30592ad0697c751d388611b37261a8445529920a..cfed8d400ad5e2741f765c7aaa0dd71e2b771950 100644 (file)
@@ -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);
index d3817bedbd5fa8704aa9ce7bc062f22f62fd6f45..5aebab650caac475f3b05600ff2a2e7e3d46f35b 100644 (file)
@@ -14,7 +14,6 @@ use strict;
 
 use DXUtil;
 
-use IO::Select;
 use DXDebug;
 use Timer;
 
index 5c3f0fb90a19c83fd59a4ffe5da2838fd90a9697..2cf7173f9c5cea358c8267670f27d029c07f0cf4 100755 (executable)
@@ -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);