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

Comparing AnyEvent-MP/MP.pm (file contents):
Revision 1.28 by root, Tue Aug 4 22:16:54 2009 UTC vs.
Revision 1.29 by root, Tue Aug 4 23:16:57 2009 UTC

43 43
44=over 4 44=over 4
45 45
46=item port 46=item port
47 47
48A port is something you can send messages to with the C<snd> function, and 48A port is something you can send messages to (with the C<snd> function).
49you can register C<rcv> handlers with. All C<rcv> handlers will receive 49
50messages they match, messages will not be queued. 50Some ports allow you to register C<rcv> handlers that can match specific
51messages. All C<rcv> handlers will receive messages they match, messages
52will not be queued.
51 53
52=item port id - C<noderef#portname> 54=item port id - C<noderef#portname>
53 55
54A port id is always the noderef, a hash-mark (C<#>) as separator, followed 56A port id is normaly the concatenation of a noderef, a hash-mark (C<#>) as
55by a port name (a printable string of unspecified format). 57separator, and a port name (a printable string of unspecified format). An
58exception is the the node port, whose ID is identical to it's node
59reference.
56 60
57=item node 61=item node
58 62
59A node is a single process containing at least one port - the node 63A node is a single process containing at least one port - the node
60port. You can send messages to node ports to let them create new ports, 64port. You can send messages to node ports to find existing ports or to
61among other things. 65create new ports, among other things.
62 66
63Initially, nodes are either private (single-process only) or hidden 67Nodes are either private (single-process only), slaves (connected to a
64(connected to a master node only). Only when they epxlicitly "become 68master node only) or public nodes (connectable from unrelated nodes).
65public" can you send them messages from unrelated other nodes.
66 69
67=item noderef - C<host:port,host:port...>, C<id@noderef>, C<id> 70=item noderef - C<host:port,host:port...>, C<id@noderef>, C<id>
68 71
69A noderef is a string that either uniquely identifies a given node (for 72A node reference is a string that either simply identifies the node (for
70private and hidden nodes), or contains a recipe on how to reach a given 73private and slave nodes), or contains a recipe on how to reach a given
71node (for public nodes). 74node (for public nodes).
75
76This recipe is simply a comma-separated list of C<address:port> pairs (for
77TCP/IP, other protocols might look different).
78
79Node references come in two flavours: resolved (containing only numerical
80addresses) or unresolved (where hostnames are used instead of addresses).
81
82Before using an unresolved node reference in a message you first have to
83resolve it.
72 84
73=back 85=back
74 86
75=head1 VARIABLES/FUNCTIONS 87=head1 VARIABLES/FUNCTIONS
76 88
91use base "Exporter"; 103use base "Exporter";
92 104
93our $VERSION = '0.1'; 105our $VERSION = '0.1';
94our @EXPORT = qw( 106our @EXPORT = qw(
95 NODE $NODE *SELF node_of _any_ 107 NODE $NODE *SELF node_of _any_
108 resolve_node
96 become_slave become_public 109 become_slave become_public
97 snd rcv mon kil reg psub 110 snd rcv mon kil reg psub
98 port 111 port
99); 112);
100 113
114identifiers become invalid. 127identifiers become invalid.
115 128
116=item $noderef = node_of $portid 129=item $noderef = node_of $portid
117 130
118Extracts and returns the noderef from a portid or a noderef. 131Extracts and returns the noderef from a portid or a noderef.
132
133=item $cv = resolve_node $noderef
134
135Takes an unresolved node reference that may contain hostnames and
136abbreviated IDs, resolves all of them and returns a resolved node
137reference.
138
139In addition to C<address:port> pairs allowed in resolved noderefs, the
140following forms are supported:
141
142=over 4
143
144=item the empty string
145
146An empty-string component gets resolved as if the default port (4040) was
147specified.
148
149=item naked port numbers (e.g. C<1234>)
150
151These are resolved by prepending the local nodename and a colon, to be
152further resolved.
153
154=item hostnames (e.g. C<localhost:1234>, C<localhost>)
155
156These are resolved by using AnyEvent::DNS to resolve them, optionally
157looking up SRV records for the C<aemp=4040> port, if no port was
158specified.
159
160=back
119 161
120=item $SELF 162=item $SELF
121 163
122Contains the current port id while executing C<rcv> callbacks or C<psub> 164Contains the current port id while executing C<rcv> callbacks or C<psub>
123blocks. 165blocks.
447 489
448=head1 FUNCTIONS FOR NODES 490=head1 FUNCTIONS FOR NODES
449 491
450=over 4 492=over 4
451 493
452=item become_public endpoint... 494=item become_public $noderef
453 495
454Tells the node to become a public node, i.e. reachable from other nodes. 496Tells the node to become a public node, i.e. reachable from other nodes.
455 497
456If no arguments are given, or the first argument is C<undef>, then 498The first argument is the (unresolved) node reference of the local node
457AnyEvent::MP tries to bind on port C<4040> on all IP addresses that the 499(if missing then the empty string is used).
458local nodename resolves to.
459 500
460Otherwise the first argument must be an array-reference with transport 501It is quite common to not specify anything, in which case the local node
461endpoints ("ip:port", "hostname:port") or port numbers (in which case the 502tries to listen on the default port, or to only specify a port number, in
462local nodename is used as hostname). The endpoints are all resolved and 503which case AnyEvent::MP tries to guess the local addresses.
463will become the node reference.
464 504
465=cut 505=cut
466 506
467=back 507=back
468 508
471Nodes understand the following messages sent to them. Many of them take 511Nodes understand the following messages sent to them. Many of them take
472arguments called C<@reply>, which will simply be used to compose a reply 512arguments called C<@reply>, which will simply be used to compose a reply
473message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and 513message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and
474the remaining arguments are simply the message data. 514the remaining arguments are simply the message data.
475 515
516While other messages exist, they are not public and subject to change.
517
476=over 4 518=over 4
477 519
478=cut 520=cut
479 521
480=item lookup => $name, @reply 522=item lookup => $name, @reply

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines