… | |
… | |
112 | |
112 | |
113 | sub connect { |
113 | sub connect { |
114 | my ($self) = @_; |
114 | my ($self) = @_; |
115 | |
115 | |
116 | return if $self->{transport}; |
116 | return if $self->{transport}; |
|
|
117 | return if $self->{connect_w}; |
117 | |
118 | |
118 | Scalar::Util::weaken $self; |
119 | Scalar::Util::weaken $self; |
119 | |
120 | |
120 | my $monitor = $AnyEvent::MP::Kernel::CONFIG->{monitor_timeout}; |
121 | my $monitor = $AnyEvent::MP::Kernel::CONFIG->{monitor_timeout}; |
121 | |
122 | |
122 | $self->{connect_to} ||= AE::timer $monitor, 0, sub { |
123 | $self->{connect_to} ||= AE::timer $monitor, 0, sub { |
123 | $self->transport_error (transport_error => $self->{id}, "unable to connect"); |
124 | $self->transport_error (transport_error => $self->{id}, "unable to connect"); |
124 | }; |
125 | }; |
125 | |
126 | |
126 | # maybe @$addresses? |
127 | # maybe @$addresses? |
127 | my @addresses = @{ |
128 | my @addresses = @{ $AnyEvent::MP::Kernel::GLOBAL_DB{"'l"}{$self->{id}} }; |
128 | $AnyEvent::MP::Kernel::GLOBAL_ADDR->{$self->{id}} |
|
|
129 | || $AnyEvent::MP::Kernel::NODE_ADDR->{$self->{id}} |
|
|
130 | }; |
|
|
131 | |
129 | |
132 | unless (@addresses) { |
130 | unless (@addresses) { |
133 | # on global nodes, all betsa re off now - we either know the node, or we don't |
131 | # on global nodes, all bets are off now - we either know the node, or we don't |
134 | unless ($AnyEvent::MP::Kernel::GLOBAL) { |
132 | unless ($AnyEvent::MP::Kernel::GLOBAL) { |
135 | $self->{connect_w} = AnyEvent::MP::Kernel::global_req ( |
133 | AnyEvent::MP::Kernel::g_find ($self->{id}); |
136 | global_find => $self->{id}, |
|
|
137 | sub { |
|
|
138 | return unless $self; # just to be sure |
|
|
139 | return unless @{ $_[0] }; |
|
|
140 | |
|
|
141 | local $AnyEvent::MP::Kernel::GLOBAL_ADDR->{$self->{id}} = $_[0]; #d# UGLY |
|
|
142 | $self->connect; |
|
|
143 | } |
|
|
144 | ); |
|
|
145 | } |
134 | } |
146 | |
|
|
147 | return; |
135 | return; |
148 | } |
136 | } |
149 | |
137 | |
150 | $self->{connect_addr} = \@addresses; # a bit weird, but efficient |
138 | $self->{connect_addr} = \@addresses; # a bit weird, but efficient |
151 | |
139 | |
… | |
… | |
158 | |
146 | |
159 | $interval = 0.4 if $interval < 0.4; |
147 | $interval = 0.4 if $interval < 0.4; |
160 | |
148 | |
161 | my @endpoints; |
149 | my @endpoints; |
162 | |
150 | |
163 | $self->{connect_w} = AE::timer 0.050 * rand, $interval * (0.9 + 0.1 * rand), sub { |
151 | $self->{connect_w} = AE::timer 0, $interval * (0.9 + 0.1 * rand), sub { |
164 | @endpoints = @addresses |
152 | @endpoints = @addresses |
165 | unless @endpoints; |
153 | unless @endpoints; |
166 | |
154 | |
167 | my $endpoint = shift @endpoints; |
155 | my $endpoint = shift @endpoints; |
168 | |
156 | |