diff --git a/clusterd/clusterd b/clusterd/clusterd index 818a145..2851a3f 100755 --- a/clusterd/clusterd +++ b/clusterd/clusterd @@ -228,24 +228,21 @@ package My::Select; our $time=Donald::Tools::uptime(); -sub My::Select::time -{ +sub My::Select::time { return $time; } our @TIMER=(); # ( [duetime,cb] , ... ) sorted by time our $active_timer_cb; -sub timeout # cb=Select::timeout(seconds,cb) -{ +sub timeout { # cb=Select::timeout(seconds,cb) my ($delta,$cb)=@_; my $duetime=$time+$delta; @TIMER=sort {$a->[0] <=> $b->[0]} ( [$duetime,$cb] , @TIMER ); return $cb; } -sub timeout_cancel # cb=Select::timeout_cancel(cb) -{ +sub timeout_cancel { # cb=Select::timeout_cancel(cb) my ($cb)=@_; @TIMER=grep {$_->[1] != $cb} @TIMER; return $cb; @@ -260,22 +257,19 @@ our @WRITER; our @EXCEPT; our $active_io; # [Handle,cb] -sub reader # cb = Select::reader(Handle,cb) -{ +sub reader { # cb = Select::reader(Handle,cb) my ($handle,$cb)=@_; push @READER,[$handle,$cb]; return $cb; } -sub writer # cb = Select::writer(Handle,cb) -{ +sub writer { # cb = Select::writer(Handle,cb) my ($handle,$cb)=@_; push @WRITER,[$handle,$cb]; return $cb; } -sub except # cb = Select::except(Handle,cb) -{ +sub except { # cb = Select::except(Handle,cb) my ($handle,$cb)=@_; push @EXCEPT,[$handle,$cb]; return $cb; @@ -285,8 +279,7 @@ sub reader_requeue {push @READER,$active_io} sub writer_requeue {push @WRITER,$active_io} sub except_requeue {push @EXCEPT,$active_io} -sub cancel # $cb = Select::cancel(cb) -{ +sub cancel { # $cb = Select::cancel(cb) my ($cb)=@_; defined $cb or $cb=$active_io->[1]; @READER=grep {$_->[1] != $cb} @READER; @@ -294,16 +287,14 @@ sub cancel # $cb = Select::cancel(cb) @EXCEPT=grep {$_->[1] != $cb} @EXCEPT; } -sub cancel_handle -{ +sub cancel_handle { my ($handle)=@_; @READER=grep {$_->[0] != $handle} @READER; @WRITER=grep {$_->[0] != $handle} @WRITER; @EXCEPT=grep {$_->[0] != $handle} @EXCEPT; } -sub run -{ +sub run { while (1) { $time=Donald::Tools::uptime(); while (@TIMER && $TIMER[0]->[0]<=$time) { @@ -359,21 +350,18 @@ our $UDP_MAX = 1472; # for broadcast on alphas our $SOL_SOCKET=1; our $SO_ERROR=4; -sub get_socket_error -{ +sub get_socket_error { my ($s)=@_; return unpack('i',getsockopt($s,$SOL_SOCKET,$SO_ERROR)); } -sub new # ( Proto=>'udp',Broadcast=>1,LocalPort=>$UDP_PORT ) -{ +sub new { # ( Proto=>'udp',Broadcast=>1,LocalPort=>$UDP_PORT ) my ($class,@args)=@_; our $socket=new IO::Socket::INET (@args) or return undef; return bless \$socket,$class; } -sub send_data -{ +sub send_data { my ($self,$ip,$port,$data)=@_; my $ip_address=inet_aton($ip); unless (defined $ip_address) {carp("can't resolve $ip\n");return undef} @@ -381,14 +369,12 @@ sub send_data $$self->send($data,0,pack_sockaddr_in($port,$ip_address)) or carp "$!\n"; } -sub reader -{ +sub reader { my ($self,$sub)=@_; My::Select::reader($$self,$sub); } -sub receive_data -{ +sub receive_data { my ($self,$cb,@args)=@_; my $receive_data_cb=sub { @@ -776,8 +762,7 @@ $ENV{'PATH'} = '/usr/local/bin:/sbin:/usr/sbin:/bin'.($ENV{PATH}?':'.$ENV{PATH}: our ($udp_peer_addr,$udp_peer_port); # ('141.14.12.12',1234) -our %UDP_HANDLER = -( +our %UDP_HANDLER = ( 'filedata' => \&udp_rx_filedata, 'filedata.2' => \&udp_rx_filedata, 'amdtardata' => \&udp_rx_amdtardata, @@ -1636,8 +1621,7 @@ sub sync_cluster_pw { # area routing -our %AREA_ROUTER = -( +our %AREA_ROUTER = ( wtf => '141.14.31.255', ); @@ -2030,8 +2014,7 @@ usage: $0 [options] __EOF__ use Getopt::Long; -GetOptions -( +GetOptions ( 'daemon' => \$options{'daemon'}, 'push=s' => \$options{'push'}, 'exec=s' => \$options{'exec'},