ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/MP/Base.pm
(Generate patch)

Comparing AnyEvent-MP/MP/Base.pm (file contents):
Revision 1.11 by root, Tue Aug 4 23:35:51 2009 UTC vs.
Revision 1.12 by root, Wed Aug 5 19:55:58 2009 UTC

34our $VERSION = '0.01'; 34our $VERSION = '0.01';
35our @EXPORT = qw( 35our @EXPORT = qw(
36 %NODE %PORT %PORT_DATA %REG $UNIQ $ID add_node 36 %NODE %PORT %PORT_DATA %REG $UNIQ $ID add_node
37 37
38 NODE $NODE node_of snd kil _any_ 38 NODE $NODE node_of snd kil _any_
39 resolve_node 39 resolve_node initialise_node
40 become_slave become_public
41); 40);
42 41
43our $DEFAULT_SECRET; 42our $DEFAULT_SECRET;
44our $DEFAULT_PORT = "4040"; 43our $DEFAULT_PORT = "4040";
45 44
249 $cv->end; 248 $cv->end;
250 249
251 $cv 250 $cv
252} 251}
253 252
254sub become_public { 253sub initialise_node($;@) {
255 return if $PUBLIC; 254 my ($noderef, @others) = @_;
256 255
257 my $noderef = join ",", @_; 256 if ($noderef =~ /^slave\/(.*)$/) {
258 my @args = @_; 257 my $name = $1;
258 $name = $UNIQ unless length $name;
259 $noderef = AE::cv;
260 $noderef->send ("slave/$name");
261 } else {
262 $noderef = resolve_node $noderef;
263 }
259 264
265 @others = map $_->recv, map +(resolve_node $_), @others;
266
260 $NODE = (resolve_node $noderef)->recv; 267 $NODE = $noderef->recv;
261 268
262 for my $t (split /,/, $NODE) { 269 for my $t (split /,/, $NODE) {
263 $NODE{$t} = $NODE{""}; 270 $NODE{$t} = $NODE{""};
264 271
265 my ($host, $port) = AnyEvent::Socket::parse_hostport $t; 272 my ($host, $port) = AnyEvent::Socket::parse_hostport $t;
266 273
267 $LISTENER{$t} = AnyEvent::MP::Transport::mp_server $host, $port, 274 $LISTENER{$t} = AnyEvent::MP::Transport::mp_server $host, $port,
268 @args,
269 sub { 275 sub {
270 my ($tp) = @_; 276 my ($tp) = @_;
271 277
272 # TODO: urgs 278 # TODO: urgs
273 my $node = add_node $tp->{remote_node}; 279 my $node = add_node $tp->{remote_node};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines