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

Comparing cvsroot/AnyEvent-MP/MP.pm (file contents):
Revision 1.3 by root, Sat Aug 1 07:11:45 2009 UTC vs.
Revision 1.5 by root, Sat Aug 1 07:44:02 2009 UTC

52 52
53Initially, nodes are either private (single-process only) or hidden 53Initially, nodes are either private (single-process only) or hidden
54(connected to a master node only). Only when they epxlicitly "become 54(connected to a master node only). Only when they epxlicitly "become
55public" can you send them messages from unrelated other nodes. 55public" can you send them messages from unrelated other nodes.
56 56
57=item noderef - C<host:port,host:port...>, C<id@noderef, C<id> 57=item noderef - C<host:port,host:port...>, C<id@noderef>, C<id>
58 58
59A noderef is a string that either uniquely identifies a given node (for 59A noderef is a string that either uniquely identifies a given node (for
60private and hidden nodes), or contains a recipe on how to reach a given 60private and hidden nodes), or contains a recipe on how to reach a given
61node (for public nodes). 61node (for public nodes).
62 62
172that Storable can serialise and deserialise is allowed, and for the local 172that Storable can serialise and deserialise is allowed, and for the local
173node, anything can be passed. 173node, anything can be passed.
174 174
175=cut 175=cut
176 176
177sub snd($@) { 177sub snd(@) {
178 my ($noderef, $port) = split /#/, shift, 2; 178 my ($noderef, $port) = split /#/, shift, 2;
179 179
180 add_node $noderef 180 add_node $noderef
181 unless exists $NODE{$noderef}; 181 unless exists $NODE{$noderef};
182 182
362 } 362 }
363 363
364 $PUBLIC = 1; 364 $PUBLIC = 1;
365} 365}
366 366
367=back
368
369=head1 NODE MESSAGES
370
371Nodes understand the following messages sent to them. Many of them take
372arguments called C<@reply>, which will simply be used to compose a reply
373message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and
374the remaining arguments are simply the message data.
375
376=over 4
377
378=cut
379
367############################################################################# 380#############################################################################
368# self node code 381# self node code
369 382
370sub _new_port($) { 383sub _new_port($) {
371 my ($name) = @_; 384 my ($name) = @_;
379} 392}
380 393
381$NODE{""} = new AnyEvent::MP::Node::Self noderef => $NODE; 394$NODE{""} = new AnyEvent::MP::Node::Self noderef => $NODE;
382_new_port ""; 395_new_port "";
383 396
397=item relay => $port, @msg
398
399Simply forwards the message to the given port.
400
401=cut
402
384rcv "", relay => \&snd; 403rcv "", relay => \&snd;
404
405=item eval => $string[ @reply]
406
407Evaluates the given string. If C<@reply> is given, then a message of the
408form C<@reply, $@, @evalres> is sent.
409
410Example: crash another node.
411
412 snd $othernode, eval => "exit";
413
414=cut
415
416rcv "", eval => sub {
417 my (undef, $string, @reply) = @_;
418 my @res = eval $string;
419 snd @reply, "$@", @res if @reply;
420};
421
422=item time => @reply
423
424Replies the the current node time to C<@reply>.
425
426Example: tell the current node to send the current time to C<$myport> in a
427C<timereply> message.
428
429 snd $NODE, time => $myport, timereply => 1, 2;
430 # => snd $myport, timereply => 1, 2, <time>
431
432=cut
433
434rcv "", time => sub { shift; snd @_, AE::time };
385 435
386=back 436=back
387 437
388=head1 SEE ALSO 438=head1 SEE ALSO
389 439

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines