/[Sack]/trunk/lib/Sack/Client.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

Contents of /trunk/lib/Sack/Client.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 228 - (show annotations)
Mon Nov 23 20:45:35 2009 UTC (14 years, 7 months ago) by dpavlin
File size: 1742 byte(s)
no transport output without $debug

1 #!/usr/bin/perl
2
3 package Sack::Client;
4
5 use warnings;
6 use strict;
7
8 use IO::Socket::INET;
9 use IO::Select;
10 use Storable qw();
11
12 use lib '/srv/Sack/lib';
13 use Data::Dump qw(dump);
14 use Sack::View;
15
16 my $port = shift @ARGV;
17 my $debug = 0;
18
19 my $sock = IO::Socket::INET->new(
20 PeerAddr => '127.0.0.1',
21 PeerPort => $port,
22 Proto => 'tcp',
23 ) || die $!;
24
25 my $sel = IO::Select->new($sock);
26 $sel->add($sock);
27
28 my $data;
29
30 while (1) {
31 for my $sock ($sel->can_read(1)) {
32 my $request = eval { Storable::fd_retrieve($sock) };
33 if ( $@ ) {
34 warn "[$port] FATAL: $@\n";
35 next;
36 }
37 warn "[$port] <<<< ", dump( keys %$request ), $/ if $debug;
38 my $response = { port => $port };
39 if ( $request->{ping} ) {
40 $response->{ping} = 'pong';
41 } elsif ( $request->{load} ) {
42 $response->{load} = 'shard';
43 } elsif ( defined $request->{shard} ) {
44 $data->{ $request->{path} } = $request->{shard};
45 $response->{load} = 'shard';
46 $response->{shard} = $request->{path};
47 } elsif ( my $code = $request->{view} ) {
48 Sack::View->code( $code );
49 foreach my $path ( keys %$data ) {
50 warn "view $request->{path} on shard $path\n";
51 die "data->{$path} not array but ",dump( $data->{$path} ) unless ref $data->{$path} eq 'ARRAY';
52 Sack::View->on_shard( $data->{$path} );
53 push @{ $response->{on_shard} }, $path;
54 }
55 $response->{out} = Sack::View->out;
56 } elsif ( defined $request->{debug} ) {
57 if ( my $eval = $request->{debug} ) {
58 warn "EVAL $eval ", dump( eval($eval) );
59 } else {
60 warn "XX data ", dump $data;
61 }
62 } elsif ( $request->{clean} ) {
63 $data = {};
64 } else {
65 $response->{error}->{unknown} = $request;
66 }
67 Storable::store_fd( $response, $sock );
68 warn "[$port] >>>> ", dump($response), $/ if $debug;
69 }
70 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26