X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXXml.pm;h=fe4cb2b8af8efc6affdc47079922e6f56f25e3c5;hb=9cc26cc7a73efb7679d3e8e819ba0019307f8607;hp=1bea12c784d38d9bda02e6cbfe1074aebb1a0312;hpb=4937d077fd03279aae2cbba6f1252ffdb04cc7a5;p=spider.git diff --git a/perl/DXXml.pm b/perl/DXXml.pm index 1bea12c7..fe4cb2b8 100644 --- a/perl/DXXml.pm +++ b/perl/DXXml.pm @@ -41,11 +41,17 @@ sub init { return unless $main::do_xml; - eval { require XML::Simple; }; - unless ($@) { + eval { require XML::Simple }; + eval { require XML::SAX } unless $@; + eval { require XML::SAX::Expat } unless $@; + if ($@) { + LogDbg('err', "do_xml was set to 1 and the XML routines failed to load ($@)"); + $main::do_xml = 0; + } else { + $XML::Simple::PREFERRED_PARSER = 'XML::SAX::Expat'; import XML::Simple; $DXProt::handle_xml = 1; - $xs = new XML::Simple(); + $xs = new XML::Simple(Cache=>[]); } undef $@; } @@ -90,8 +96,44 @@ sub normal # # note that this a function not a method # + +my $last10; +my $last_hour; + sub process { + my $t = time; + my @dxchan = DXChannel::get_all(); + my $dxchan; + + foreach $dxchan (@dxchan) { + next unless $dxchan->is_node; + next unless $dxchan->handle_xml; + next if $dxchan == $main::me; + + # send a ping out on this channel + if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) { + if ($dxchan->{nopings} <= 0) { + $dxchan->disconnect; + } else { + DXXml::Ping::add($main::me, $dxchan->call); + $dxchan->{nopings} -= 1; + $dxchan->{lastping} = $t; + $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}}; + } + } + } + + + # every ten seconds + if (!$last10 || $t - $last10 >= 10) { + $last10 = $t; + } + + # every hour + if (!$last_hour || $main::systime - 3600 > $last_hour) { + $last_hour = $main::systime; + } } @@ -119,10 +161,10 @@ sub toxml unless (exists $self->{'-xml'}) { $self->{o} ||= $main::mycall; - $self->{t} ||= IsoTime::dayms(); + $self->{t} ||= IsoTime::dayminsec(); $self->{id} ||= nextid(); - my ($name) = ref $self =~ /::(\w+)$/; + my ($name) = (ref $self) =~ /::(\w+)$/; $self->{'-xml'} = $xs->XMLout($self, RootName =>lc $name, NumericEscape=>1); } return $self->{'-xml'};