… | |
… | |
40 | sub send { |
40 | sub send { |
41 | &{ shift->{send} } |
41 | &{ shift->{send} } |
42 | } |
42 | } |
43 | |
43 | |
44 | # nodes reachable via the network |
44 | # nodes reachable via the network |
45 | package AnyEvent::MP::Node::External; |
45 | package AnyEvent::MP::Node::Remote; |
46 | |
46 | |
47 | use base "AnyEvent::MP::Node"; |
47 | use base "AnyEvent::MP::Node"; |
48 | |
48 | |
49 | # called at init time, mostly sets {send} |
49 | # called at init time, mostly sets {send} |
50 | sub transport_reset { |
50 | sub transport_reset { |
… | |
… | |
109 | $transport_send->($_) |
109 | $transport_send->($_) |
110 | for @{ delete $self->{queue} || [] }; |
110 | for @{ delete $self->{queue} || [] }; |
111 | } |
111 | } |
112 | |
112 | |
113 | sub connect { |
113 | sub connect { |
114 | my ($self, @addresses) = @_; |
114 | my ($self) = @_; |
115 | |
115 | |
116 | return if $self->{transport}; |
116 | return if $self->{transport}; |
117 | |
117 | |
118 | Scalar::Util::weaken $self; |
118 | Scalar::Util::weaken $self; |
119 | |
119 | |
… | |
… | |
121 | |
121 | |
122 | $self->{connect_to} ||= AE::timer $monitor, 0, sub { |
122 | $self->{connect_to} ||= AE::timer $monitor, 0, sub { |
123 | $self->transport_error (transport_error => $self->{id}, "unable to connect"); |
123 | $self->transport_error (transport_error => $self->{id}, "unable to connect"); |
124 | }; |
124 | }; |
125 | |
125 | |
|
|
126 | # maybe @$addresses? |
|
|
127 | my @addresses = @{ |
|
|
128 | $AnyEvent::MP::Kernel::GLOBAL_ADDR->{$self->{id}} |
|
|
129 | || $AnyEvent::MP::Kernel::NODE_ADDR->{$self->{id}} |
|
|
130 | }; |
|
|
131 | |
126 | return unless @addresses; |
132 | unless (@addresses) { |
|
|
133 | # on global nodes, all betsa re off now - we either know the node, or we don't |
|
|
134 | unless ($AnyEvent::MP::Kernel::GLOBAL) { |
|
|
135 | $self->{connect_w} = AnyEvent::MP::Kernel::global_req ( |
|
|
136 | global_find => $self->{id}, |
|
|
137 | sub { |
|
|
138 | return unless $self; # just to be sure |
|
|
139 | return unless @{ $_[0] }; |
127 | |
140 | |
128 | if ($self->{connect_w}) { |
141 | local $AnyEvent::MP::Kernel::GLOBAL_ADDR->{$self->{id}} = $_[0]; #d# UGLY |
129 | # sometimes we get told about new addresses after we started to connect |
142 | $self->connect; |
130 | unshift @{$self->{connect_addr}}, @addresses; |
143 | } |
|
|
144 | ); |
|
|
145 | } |
|
|
146 | |
131 | return; |
147 | return; |
132 | } |
148 | } |
133 | |
149 | |
134 | $self->{connect_addr} = \@addresses; # a bit weird, but efficient |
150 | $self->{connect_addr} = \@addresses; # a bit weird, but efficient |
135 | |
151 | |
… | |
… | |
164 | } |
180 | } |
165 | |
181 | |
166 | sub kill { |
182 | sub kill { |
167 | my ($self, $port, @reason) = @_; |
183 | my ($self, $port, @reason) = @_; |
168 | |
184 | |
169 | $self->send (["", kil => $port, @reason]); |
185 | $self->{send} (["", kil => $port, @reason]); |
170 | } |
186 | } |
171 | |
187 | |
172 | sub monitor { |
188 | sub monitor { |
173 | my ($self, $portid, $cb) = @_; |
189 | my ($self, $portid, $cb) = @_; |
174 | |
190 | |
… | |
… | |
191 | unless (@$list) { |
207 | unless (@$list) { |
192 | $self->send (["", mon0 => $portid]); |
208 | $self->send (["", mon0 => $portid]); |
193 | delete $self->{monitor}{$portid}; |
209 | delete $self->{monitor}{$portid}; |
194 | } |
210 | } |
195 | } |
211 | } |
196 | |
|
|
197 | # used for direct slave connections as well |
|
|
198 | package AnyEvent::MP::Node::Direct; |
|
|
199 | |
|
|
200 | use base "AnyEvent::MP::Node::External"; |
|
|
201 | |
212 | |
202 | package AnyEvent::MP::Node::Self; |
213 | package AnyEvent::MP::Node::Self; |
203 | |
214 | |
204 | use base "AnyEvent::MP::Node"; |
215 | use base "AnyEvent::MP::Node"; |
205 | |
216 | |