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.7 by root, Tue Aug 4 14:10:51 2009 UTC vs.
Revision 1.8 by root, Tue Aug 4 18:33:30 2009 UTC

31 31
32use base "Exporter"; 32use base "Exporter";
33 33
34our $VERSION = '0.01'; 34our $VERSION = '0.01';
35our @EXPORT = qw( 35our @EXPORT = qw(
36 %NODE %PORT %PORT_DATA %REG $UNIQ $ID add_node
37
36 NODE $NODE snd kil _any_ 38 NODE $NODE node_of snd kil _any_
37 become_slave become_public 39 become_slave become_public
38); 40);
39 41
40our $DEFAULT_SECRET; 42our $DEFAULT_SECRET;
41 43
50The default simply logs the message to STDERR. 52The default simply logs the message to STDERR.
51 53
52=cut 54=cut
53 55
54our $WARN = sub { 56our $WARN = sub {
57 my $msg = $_[0];
58 $msg =~ s/\n$//;
55 warn "$_[0]\n"; 59 warn "$msg\n";
56}; 60};
57 61
58sub nonce($) { 62sub nonce($) {
59 my $nonce; 63 my $nonce;
60 64
94 98
95our $UNIQ = gen_uniq; # per-process/node unique cookie 99our $UNIQ = gen_uniq; # per-process/node unique cookie
96our $ID = "a"; 100our $ID = "a";
97our $PUBLIC = 0; 101our $PUBLIC = 0;
98our $NODE = $$; 102our $NODE = $$;
99our $PORT;
100 103
101our %NODE; # node id to transport mapping, or "undef", for local node 104our %NODE; # node id to transport mapping, or "undef", for local node
102our %PORT; # local ports 105our (%PORT, %PORT_DATA); # local ports
103 106
104our %RMON; # local ports monitored by remote nodes ($RMON{noderef}{portid} == cb) 107our %RMON; # local ports monitored by remote nodes ($RMON{noderef}{portid} == cb)
105our %LMON; # monitored _local_ ports 108our %LMON; # monitored _local_ ports
106 109
107our %WKP; 110our %REG; # registered port names
108our %LISTENER; # local transports 111
112our %LISTENER;
109 113
110our $SRCNODE; # holds the sending node during _inject 114our $SRCNODE; # holds the sending node during _inject
111 115
112sub NODE() { $NODE } 116sub NODE() {
117 $NODE
118}
119
120sub node_of($) {
121 my ($noderef, undef) = split /#/, $_[0], 2;
122
123 $noderef
124}
113 125
114sub _ANY_() { 1 } 126sub _ANY_() { 1 }
115sub _any_() { \&_ANY_ } 127sub _any_() { \&_ANY_ }
116 128
117sub _inject { 129sub _inject {
143 155
144 ($NODE{$noderef} || add_node $noderef) 156 ($NODE{$noderef} || add_node $noderef)
145 ->send ([$port, @_]); 157 ->send ([$port, @_]);
146} 158}
147 159
148sub kil($) { 160sub kil(@) {
149 my ($noderef, $port) = split /#/, shift, 2; 161 my ($noderef, $port) = split /#/, shift, 2;
150 162
151 ($NODE{$noderef} || add_node $noderef) 163 ($NODE{$noderef} || add_node $noderef)
152 ->kill ($port, @_); 164 ->kill ($port, @_);
153} 165}
192 }, 204 },
193 mon1 => sub { # enable monitoring 205 mon1 => sub { # enable monitoring
194 my $portid = shift; 206 my $portid = shift;
195 my $node = $SRCNODE; 207 my $node = $SRCNODE;
196 $NODE{""}->monitor ($portid, $node->{rmon}{$portid} = sub { 208 $NODE{""}->monitor ($portid, $node->{rmon}{$portid} = sub {
197 $node->send (["", kil => $portid]); 209 $node->send (["", kil => $portid, @_]);
198 }); 210 });
199 }, 211 },
200 kil => sub { 212 kil => sub {
201 my $cbs = delete $SRCNODE->{lmon}{$_[0]} 213 my $cbs = delete $SRCNODE->{lmon}{+shift}
202 or return; 214 or return;
203 215
204 $_->() for @$cbs; 216 $_->(@_) for @$cbs;
205 }, 217 },
206 218
207 # well-known-port lookup 219 # well-known-port lookup
208 wkp => sub { 220 lookup => sub {
209 my $wkname = shift; 221 my $name = shift;
210 snd @_, $WKP{$wkname}; 222 my $port = $REG{$name};
223 #TODO: check vailidity
224 snd @_, $port;
211 }, 225 },
212 226
213 # relay message to another node / generic echo 227 # relay message to another node / generic echo
214 relay => sub { 228 relay => sub {
215 &snd; 229 &snd;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines