/[Sack]/trunk/lib/Sack/Server.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Sack/Server.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/experiments/protocol-v3/server.pl revision 175 by dpavlin, Tue Nov 3 18:02:33 2009 UTC trunk/lib/Sack/Server.pm revision 189 by dpavlin, Sun Nov 8 13:44:10 2009 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
2    
3    package Sack::Server;
4    
5  use warnings;  use warnings;
6  use strict;  use strict;
7    
# Line 9  use IO::Select; Line 11  use IO::Select;
11  use Data::Dump qw(dump);  use Data::Dump qw(dump);
12  use Storable qw();  use Storable qw();
13  use File::Slurp;  use File::Slurp;
14    use Cwd qw(abs_path);
15    
16  my @cloud = qw(localhost tab.lan llin.lan);  my @cloud;
17    my $cloud_path = $ENV{CLOUD} || die "start with: CLOUD=etc/cloud perl -I/srv/Sack/lib $0\n";
 my $cloud_path = $ENV{CLOUD} || '/srv/Sack/etc/lib';  
18  @cloud = read_file $cloud_path;  @cloud = read_file $cloud_path;
19  @cloud = map { chomp $_; $_ } @cloud;  @cloud = map { chomp $_; $_ } @cloud;
20    
# Line 20  warn "# cloud ",dump( @cloud ); Line 22  warn "# cloud ",dump( @cloud );
22    
23  my $listen_port = 4444;  my $listen_port = 4444;
24    
25  my $node_path = $0;  my $node_path = abs_path $0;
26  $node_path =~ s{server.pl}{client.pl};  $node_path =~ s{Server}{Client};
27    
28  my $lsn = IO::Socket::INET->new(Listen => 1, LocalPort => $listen_port, Reuse => 1) or die $!;  my $lsn = IO::Socket::INET->new(Listen => 1, LocalPort => $listen_port, Reuse => 1) or die $!;
29  my $sel = IO::Select->new($lsn);  my $sel = IO::Select->new($lsn);
# Line 32  sub info { Line 34  sub info {
34          push @{ $info->{$port} }, [ @_ ];          push @{ $info->{$port} }, [ @_ ];
35  }  }
36    
37  sub fork_node {  sub fork_ssh {
38          my ( $port, $host ) = @_;          my ( $port, $host ) = @_;
39    
40          if ( my $pid = fork ) {          if ( my $pid = fork ) {
# Line 54  sub fork_node { Line 56  sub fork_node {
56  my $node_port = 4000;  my $node_port = 4000;
57    
58  foreach my $host ( @cloud ) {  foreach my $host ( @cloud ) {
59          system "echo $node_path | cpio --create --dereference | ssh -T -F $cloud_path.ssh $host cpio --extract --make-directories --unconditional --verbose";          system "find /srv/Sack/ | cpio --create --dereference | ssh -T -F $cloud_path.ssh $host cpio --extract --make-directories --unconditional";
60          fork_node( $node_port++, $host );          fork_ssh( $node_port++, $host );
61  }  }
62    
63  my $session;  my $session;
64    
65    sub to_all {
66            my $data = shift;
67            foreach my $port ( keys %{ $session->{port} } ) {
68                    warn ">>>> [$port]\n";
69                    Storable::store_fd( $data, $session->{port}->{$port} );
70            }
71    }
72    
73  while (1) {  while (1) {
74          for my $sock ($sel->can_read(1)) {          for my $sock ($sel->can_read(1)) {
75                  if ($sock == $lsn) {                  if ($sock == $lsn) {
# Line 81  while (1) { Line 91  while (1) {
91                                  if ( $data->{repl} ) {                                  if ( $data->{repl} ) {
92                                          my $response = { repl => $$ };                                          my $response = { repl => $$ };
93                                          if ( $data->{repl} =~ m/ping/ ) {                                          if ( $data->{repl} =~ m/ping/ ) {
94                                                  foreach my $port ( keys %{ $session->{port} } ) {                                                  to_all { ping => 1 };
                                                         warn ">>>> [$port]\n";  
                                                         Storable::store_fd( { ping => 1 }, $session->{port}->{$port} );  
                                                 }  
95                                          } elsif ( $data->{repl} =~ m/info/ ) {                                          } elsif ( $data->{repl} =~ m/info/ ) {
96                                                  $response->{info} = $info;                                                  $response->{info} = $info;
97                                            } else {
98                                                    $response->{error}->{unknown} = $data;
99                                          }                                          }
100                                          Storable::store_fd( $response, $sock );                                          Storable::store_fd( $response, $sock );
101                                  } elsif ( $data->{ping} ) {                                  } elsif ( $data->{ping} ) {

Legend:
Removed from v.175  
changed lines
  Added in v.189

  ViewVC Help
Powered by ViewVC 1.1.26