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.17 by root, Sun Aug 9 16:08:16 2009 UTC vs.
Revision 1.18 by root, Mon Aug 10 01:37:19 2009 UTC

40); 40);
41 41
42our $DEFAULT_SECRET; 42our $DEFAULT_SECRET;
43our $DEFAULT_PORT = "4040"; 43our $DEFAULT_PORT = "4040";
44 44
45our $CONNECT_INTERVAL = 5; # new connect every 5s, at least 45our $CONNECT_INTERVAL = 2; # new connect every 2s, at least
46our $CONNECT_TIMEOUT = 30; # includes handshake 46our $CONNECT_TIMEOUT = 5; # includes handshake
47our $CONNECT_TIMEOUT_MAX = 90; # never retry less often
47 48
48=item $AnyEvent::MP::Base::WARN 49=item $AnyEvent::MP::Base::WARN
49 50
50This value is called with an error or warning message, when e.g. a connection 51This value is called with an error or warning message, when e.g. a connection
51could not be created, authorisation failed and so on. 52could not be created, authorisation failed and so on.
123our %NODE; # node id to transport mapping, or "undef", for local node 124our %NODE; # node id to transport mapping, or "undef", for local node
124our (%PORT, %PORT_DATA); # local ports 125our (%PORT, %PORT_DATA); # local ports
125 126
126our %RMON; # local ports monitored by remote nodes ($RMON{noderef}{portid} == cb) 127our %RMON; # local ports monitored by remote nodes ($RMON{noderef}{portid} == cb)
127our %LMON; # monitored _local_ ports 128our %LMON; # monitored _local_ ports
128
129our %REG; # registered port names
130 129
131our %LISTENER; 130our %LISTENER;
132 131
133our $SRCNODE; # holds the sending node during _inject 132our $SRCNODE; # holds the sending node during _inject
134 133
317 } 316 }
318 317
319 (add_node $_)->connect for @others; 318 (add_node $_)->connect for @others;
320 319
321 if ($SLAVE) { 320 if ($SLAVE) {
321 my $timeout = AE::timer $CONNECT_TIMEOUT, 0, sub { $SLAVE->() };
322 $SLAVE->recv; 322 $SLAVE->recv
323 or Carp::croak "AnyEvent::MP: unable to enter slave mode, unable to connect to a seednode.\n";
323 $SLAVE = 1; 324 $SLAVE = 1;
324 } 325 }
325} 326}
326 327
327############################################################################# 328#############################################################################
332 333
333 unless (defined &$func) { 334 unless (defined &$func) {
334 my $pkg = $func; 335 my $pkg = $func;
335 do { 336 do {
336 $pkg =~ s/::[^:]+$// 337 $pkg =~ s/::[^:]+$//
337 or return sub { die "unable to resolve $func" }; 338 or return sub { die "unable to resolve '$func'" };
338 eval "require $pkg"; 339 eval "require $pkg";
339 } until defined &$func; 340 } until defined &$func;
340 } 341 }
341 342
342 \&$func 343 \&$func
370 $NODE{$_[0]} = $SRCNODE; 371 $NODE{$_[0]} = $SRCNODE;
371 }, 372 },
372 373
373 # public services 374 # public services
374 375
375 # well-known-port lookup
376 lookup => sub {
377 my $name = shift;
378 my $port = $REG{$name};
379 #TODO: check validity
380 snd @_, $port;
381 },
382
383 # relay message to another node / generic echo 376 # relay message to another node / generic echo
384 relay => sub { 377 relay => sub {
385 &snd; 378 &snd;
386 }, 379 },
387 relay_multiple => sub { 380 relay_multiple => sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines