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

Comparing AnyEvent-MP/MP/Kernel.pm (file contents):
Revision 1.33 by root, Sun Aug 30 19:49:47 2009 UTC vs.
Revision 1.34 by root, Mon Aug 31 10:07:04 2009 UTC

38our $VERSION = '0.9'; 38our $VERSION = '0.9';
39our @EXPORT = qw( 39our @EXPORT = qw(
40 %NODE %PORT %PORT_DATA $UNIQ $RUNIQ $ID 40 %NODE %PORT %PORT_DATA $UNIQ $RUNIQ $ID
41 add_node load_func snd_to_func snd_on eval_on 41 add_node load_func snd_to_func snd_on eval_on
42 42
43 NODE $NODE node_of snd kil 43 NODE $NODE node_of snd kil port_is_local
44 port_is_local 44 configure
45 resolve_node initialise_node
46 known_nodes up_nodes mon_nodes node_is_known node_is_up 45 known_nodes up_nodes mon_nodes node_is_known node_is_up
47); 46);
48
49our $DEFAULT_PORT = "4040";
50 47
51our $CONNECT_INTERVAL = 2; # new connect every 2s, at least 48our $CONNECT_INTERVAL = 2; # new connect every 2s, at least
52our $NETWORK_LATENCY = 3; # activity timeout 49our $NETWORK_LATENCY = 3; # activity timeout
53our $MONITOR_TIMEOUT = 15; # fail monitoring after this time 50our $MONITOR_TIMEOUT = 15; # fail monitoring after this time
54 51
283 push @refs, $_->[1] unless $seen{$_->[1]}++ 280 push @refs, $_->[1] unless $seen{$_->[1]}++
284 } 281 }
285 shift->send (@refs); 282 shift->send (@refs);
286 }); 283 });
287 284
288 $nodeid = $DEFAULT_PORT unless length $nodeid;
289
290 my $idx; 285 my $idx;
291 for my $t (split /,/, $nodeid) { 286 for my $t (split /,/, $nodeid) {
292 my $pri = ++$idx; 287 my $pri = ++$idx;
293 288
294 $t = length $t ? _nodename . ":$t" : _nodename 289 $t = length $t ? _nodename . ":$t" : _nodename
295 if $t =~ /^\d*$/; 290 if $t =~ /^\d*$/;
296 291
297 my ($host, $port) = AnyEvent::Socket::parse_hostport $t, "aemp=$DEFAULT_PORT" 292 my ($host, $port) = AnyEvent::Socket::parse_hostport $t, 0
298 or Carp::croak "$t: unparsable transport descriptor"; 293 or Carp::croak "$t: unparsable transport descriptor";
299 294
300 $port = "0" if $port eq "*"; 295 $port = "0" if $port eq "*";
301 296
302 if ($host eq "*") { 297 if ($host eq "*") {
351 $cv->end; 346 $cv->end;
352 347
353 $cv 348 $cv
354} 349}
355 350
356sub initialise_node(;$%) { 351sub configure(%) {
357 my ($profile, %kv) = @_; 352 my (%kv) = @_;
353
354 my $profile = delete $kv{profile};
358 355
359 $profile = _nodename 356 $profile = _nodename
360 unless defined $profile; 357 unless defined $profile;
361 358
362 $CONFIG = AnyEvent::MP::Config::find_profile $profile, %kv; 359 $CONFIG = AnyEvent::MP::Config::find_profile $profile, %kv;
380 377
381 for (map _resolve $_, @$binds) { 378 for (map _resolve $_, @$binds) {
382 for my $bind ($_->recv) { 379 for my $bind ($_->recv) {
383 my ($host, $port) = AnyEvent::Socket::parse_hostport $bind 380 my ($host, $port) = AnyEvent::Socket::parse_hostport $bind
384 or Carp::croak "$bind: unparsable local bind address"; 381 or Carp::croak "$bind: unparsable local bind address";
385
386 $port =~ s/^.*=//; # remove bogus aemp=
387 382
388 my $listener = AnyEvent::MP::Transport::mp_server 383 my $listener = AnyEvent::MP::Transport::mp_server
389 $host, 384 $host,
390 $port, 385 $port,
391 prepare => sub { 386 prepare => sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines