Skip to content

Commit

Permalink
clusters: Move brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
donald committed Jan 27, 2025
1 parent e70be20 commit cacf391
Showing 1 changed file with 17 additions and 34 deletions.
51 changes: 17 additions & 34 deletions clusterd/clusterd
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -285,25 +279,22 @@ 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;
@WRITER=grep {$_->[1] != $cb} @WRITER;
@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) {
Expand Down Expand Up @@ -359,36 +350,31 @@ 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}
unless (length($data)<=$UDP_MAX) {carp("message to long\n");return undef}
$$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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1636,8 +1621,7 @@ sub sync_cluster_pw {

# area routing

our %AREA_ROUTER =
(
our %AREA_ROUTER = (
wtf => '141.14.31.255',
);

Expand Down Expand Up @@ -2030,8 +2014,7 @@ usage: $0 [options]
__EOF__

use Getopt::Long;
GetOptions
(
GetOptions (
'daemon' => \$options{'daemon'},
'push=s' => \$options{'push'},
'exec=s' => \$options{'exec'},
Expand Down

0 comments on commit cacf391

Please sign in to comment.