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

Comparing AnyEvent-MP/MP/Node.pm (file contents):
Revision 1.32 by root, Sun Aug 30 09:24:09 2009 UTC vs.
Revision 1.33 by root, Sun Aug 30 21:45:51 2009 UTC

116 116
117 return if $self->{transport}; 117 return if $self->{transport};
118 118
119 Scalar::Util::weaken $self; 119 Scalar::Util::weaken $self;
120 120
121 $self->{connect_to} ||= AE::timer
122 $AnyEvent::MP::Config::CFG{monitor_timeout} || $AnyEvent::MP::Kernel::MONITOR_TIMEOUT, 121 my $monitor = $AnyEvent::MP::Config::CFG{monitor_timeout} || $AnyEvent::MP::Kernel::MONITOR_TIMEOUT;
123 0, 122
124 sub { 123 $self->{connect_to} ||= AE::timer $monitor, 0, sub {
125 $self->transport_error (transport_error => $self->{id}, "unable to connect"); 124 $self->transport_error (transport_error => $self->{id}, "unable to connect");
125 };
126
127 return unless @addresses;
128 return if $self->{connect_w};
129
130 $AnyEvent::MP::Kernel::WARN->(9, "connecting to $self->{id} with [@addresses]");
131
132 my $interval = $AnyEvent::MP::Config::CFG{connect_interval} || $AnyEvent::MP::Kernel::CONNECT_INTERVAL;
133
134 $interval = ($monitor - $interval) / @addresses
135 if ($monitor - $interval) / @addresses < $interval;
136
137 $interval = 0.4 if $interval < 0.4;
138
139 my @endpoints;
140
141 $self->{connect_w} = AE::timer rand, $interval, sub {
142 @endpoints = @addresses
143 unless @endpoints;
144
145 my $endpoint = shift @endpoints;
146
147 $AnyEvent::MP::Kernel::WARN->(9, "connecting to $self->{id} at $endpoint");
148
149 $self->{trial}{$endpoint} ||= do {
150 my ($host, $port) = AnyEvent::Socket::parse_hostport $endpoint
151 or return $AnyEvent::MP::Kernel::WARN->(1, "$self->{id}: not a resolved node reference.");
152
153 AnyEvent::MP::Transport::mp_connect
154 $host, $port,
155 sub { delete $self->{trial}{$endpoint} },
126 }; 156 };
127
128 return unless @addresses;
129
130 $AnyEvent::MP::Kernel::WARN->(9, "connecting to $self->{id} with [@addresses]");
131
132 unless ($self->{connect_w}) {
133 my @endpoints;
134
135 $self->{connect_w} = AE::timer
136 rand,
137 $AnyEvent::MP::Config::CFG{connect_interval} || $AnyEvent::MP::Kernel::CONNECT_INTERVAL,
138 sub {
139 @endpoints = @addresses
140 unless @endpoints;
141
142 my $endpoint = shift @endpoints;
143
144 $AnyEvent::MP::Kernel::WARN->(9, "connecting to $self->{id} at $endpoint");
145
146 $self->{trial}{$endpoint} ||= do {
147 my ($host, $port) = AnyEvent::Socket::parse_hostport $endpoint
148 or return $AnyEvent::MP::Kernel::WARN->(1, "$self->{id}: not a resolved node reference.");
149
150 AnyEvent::MP::Transport::mp_connect
151 $host, $port,
152 sub { delete $self->{trial}{$endpoint} },
153 };
154 }
155 ;
156 } 157 };
157} 158}
158 159
159sub kill { 160sub kill {
160 my ($self, $port, @reason) = @_; 161 my ($self, $port, @reason) = @_;
161 162

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines