… | |
… | |
39 | our @EXPORT = qw( |
39 | our @EXPORT = qw( |
40 | %NODE %PORT %PORT_DATA $UNIQ $RUNIQ $ID |
40 | %NODE %PORT %PORT_DATA $UNIQ $RUNIQ $ID |
41 | connect_node add_node load_func snd_to_func |
41 | connect_node add_node load_func snd_to_func |
42 | |
42 | |
43 | NODE $NODE node_of snd kil |
43 | NODE $NODE node_of snd kil |
|
|
44 | port_is_local |
44 | resolve_node initialise_node |
45 | resolve_node initialise_node |
45 | known_nodes up_nodes mon_nodes node_is_known node_is_up |
46 | known_nodes up_nodes mon_nodes node_is_known node_is_up |
46 | ); |
47 | ); |
47 | |
48 | |
48 | our $DEFAULT_PORT = "4040"; |
49 | our $DEFAULT_PORT = "4040"; |
… | |
… | |
175 | my ($noderef, undef) = split /#/, $_[0], 2; |
176 | my ($noderef, undef) = split /#/, $_[0], 2; |
176 | |
177 | |
177 | $noderef |
178 | $noderef |
178 | } |
179 | } |
179 | |
180 | |
180 | sub TRACE() { 0 } |
181 | BEGIN { |
|
|
182 | *TRACE = $ENV{PERL_ANYEVENT_MP_TRACE} |
|
|
183 | ? sub () { 1 } |
|
|
184 | : sub () { 0 }; |
|
|
185 | } |
181 | |
186 | |
182 | sub _inject { |
187 | sub _inject { |
183 | warn "RCV $SRCNODE->{noderef} -> @_\n" if TRACE;#d# |
188 | warn "RCV $SRCNODE->{noderef} -> @_\n" if TRACE;#d# |
184 | &{ $PORT{+shift} or return }; |
189 | &{ $PORT{+shift} or return }; |
185 | } |
190 | } |
… | |
… | |
231 | |
236 | |
232 | warn "SND $noderef <- $portid @_\n" if TRACE;#d# |
237 | warn "SND $noderef <- $portid @_\n" if TRACE;#d# |
233 | |
238 | |
234 | ($NODE{$noderef} || add_node $noderef) |
239 | ($NODE{$noderef} || add_node $noderef) |
235 | ->{send} (["$portid", @_]); |
240 | ->{send} (["$portid", @_]); |
|
|
241 | } |
|
|
242 | |
|
|
243 | =item $is_local = port_is_local $port |
|
|
244 | |
|
|
245 | Returns true iff the port is a local port. |
|
|
246 | |
|
|
247 | =cut |
|
|
248 | |
|
|
249 | sub port_is_local($) { |
|
|
250 | my ($noderef, undef) = split /#/, $_[0], 2; |
|
|
251 | |
|
|
252 | $NODE{$noderef} == $NODE{""} |
236 | } |
253 | } |
237 | |
254 | |
238 | =item snd_to_func $noderef, $func, @args |
255 | =item snd_to_func $noderef, $func, @args |
239 | |
256 | |
240 | Expects a noderef and a name of a function. Asynchronously tries to call |
257 | Expects a noderef and a name of a function. Asynchronously tries to call |
… | |
… | |
339 | |
356 | |
340 | @others = map $_->recv, map +(resolve_node $_), @others; |
357 | @others = map $_->recv, map +(resolve_node $_), @others; |
341 | |
358 | |
342 | $NODE = $noderef->recv; |
359 | $NODE = $noderef->recv; |
343 | |
360 | |
|
|
361 | $NODE{$NODE} = $NODE{""}; |
|
|
362 | |
344 | for my $t (split /,/, $NODE) { |
363 | for my $t (split /,/, $NODE) { |
345 | $NODE{$t} = $NODE{""}; |
364 | $NODE{$t} = $NODE{""}; |
346 | |
365 | |
347 | my ($host, $port) = AnyEvent::Socket::parse_hostport $t; |
366 | my ($host, $port) = AnyEvent::Socket::parse_hostport $t; |
348 | |
367 | |