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.50 by root, Wed Dec 30 15:49:05 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 # maybe always delay, too?
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 # no need to always delay
274 271 if ($DELAY_W) {
275 my $delay_cb = sub { 272 my @args = @_;
276 delete $AnyEvent::MP::Kernel::LMON{$portid}{$cb+0}; 273 push @DELAY, sub { AnyEvent::MP::Kernel::_unmonitor (@args) };
274 return;
277 }; 275 }
278 276
279 $DELAY_W ? push @DELAY, $delay_cb : &$delay_cb; 277 &AnyEvent::MP::Kernel::_unmonitor;
280} 278}
281 279
282=head1 SEE ALSO 280=head1 SEE ALSO
283 281
284L<AnyEvent::MP>. 282L<AnyEvent::MP>.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines