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.48 by root, Wed Dec 30 13:37:53 2009 UTC vs.
Revision 1.49 by root, Wed Dec 30 15:33:08 2009 UTC

245 245
246 $AnyEvent::MP::Kernel::WARN->(9, "I refuse to talk to myself ($tp->{peerhost}:$tp->{peerport})"); 246 $AnyEvent::MP::Kernel::WARN->(9, "I refuse to talk to myself ($tp->{peerhost}:$tp->{peerport})");
247} 247}
248 248
249sub kill { 249sub kill {
250 my ($self, @args) = @_; 250 my (undef, @args) = @_;
251 251
252 # we _always_ delay kil's, to avoid calling mon callbacks 252 # we _always_ delay kil's, to avoid calling mon callbacks
253 # from anything but the event loop context. 253 # from anything but the event loop context.
254 $DELAY = 1; 254 $DELAY = 1;
255 push @DELAY, sub { AnyEvent::MP::Kernel::_kill (@args) }; 255 push @DELAY, sub { AnyEvent::MP::Kernel::_kill (@args) };
256 $DELAY_W ||= AE::timer 0, 0, \&_send_delayed; 256 $DELAY_W ||= AE::timer 0, 0, \&_send_delayed;
257} 257}
258 258
259sub monitor { 259sub monitor {
260 my ($self, $portid, $cb) = @_; 260 # shortcut
261 261 if ($DELAY_W) {
262 my $delay_cb = sub { 262 my @args = @_;
263 return $cb->(no_such_port => "cannot monitor nonexistent port", "$self->{id}#$portid") 263 push @DELAY, sub { AnyEvent::MP::Kernel::_monitor (@args) };
264 unless exists $AnyEvent::MP::Kernel::PORT{$portid}; 264 return;
265
266 $AnyEvent::MP::Kernel::LMON{$portid}{$cb+0} = $cb;
267 }; 265 }
268 266 &AnyEvent::MP::Kernel::_monitor;
269 $DELAY_W ? push @DELAY, $delay_cb : &$delay_cb;
270} 267}
271 268
272sub unmonitor { 269sub unmonitor {
273 my ($self, $portid, $cb) = @_; 270 if ($DELAY_W) {
274 271 my @args = @_;
275 my $delay_cb = sub { 272 push @DELAY, sub { AnyEvent::MP::Kernel::_unmonitor (@args) };
276 delete $AnyEvent::MP::Kernel::LMON{$portid}{$cb+0}; 273 return;
277 }; 274 }
278 275
279 $DELAY_W ? push @DELAY, $delay_cb : &$delay_cb; 276 &AnyEvent::MP::Kernel::_unmonitor;
280} 277}
281 278
282=head1 SEE ALSO 279=head1 SEE ALSO
283 280
284L<AnyEvent::MP>. 281L<AnyEvent::MP>.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines