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.41 by root, Fri Sep 11 02:32:23 2009 UTC vs.
Revision 1.49 by root, Wed Dec 30 15:33:08 2009 UTC

100 100
101 $self->{transport} = $transport; 101 $self->{transport} = $transport;
102 102
103 my $transport_send = $transport->can ("send"); 103 my $transport_send = $transport->can ("send");
104 104
105 AnyEvent::MP::Kernel::_inject_nodeevent ($self, 1);
106
105 $self->{send} = sub { 107 $self->{send} = sub {
106 $transport_send->($transport, $_[0]); 108 $transport_send->($transport, $_[0]);
107 }; 109 };
108
109 AnyEvent::MP::Kernel::_inject_nodeevent ($self, 1);
110 110
111 $transport->send ($_) 111 $transport->send ($_)
112 for @{ delete $self->{queue} || [] }; 112 for @{ delete $self->{queue} || [] };
113} 113}
114 114
208sub connect { 208sub connect {
209 # we are trivially connected 209 # we are trivially connected
210} 210}
211 211
212# delay every so often to avoid recursion, also used to delay after spawn 212# delay every so often to avoid recursion, also used to delay after spawn
213our $DELAY; 213our $DELAY = -50;
214our @DELAY; 214our @DELAY;
215our $DELAY_W; 215our $DELAY_W;
216 216
217sub _send_delayed { 217sub _send_delayed {
218 local $AnyEvent::MP::Kernel::SRCNODE = $AnyEvent::MP::Kernel::NODE{""}; 218 local $AnyEvent::MP::Kernel::SRCNODE = $AnyEvent::MP::Kernel::NODE{""};
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, $port, @reason) = @_; 250 my (undef, @args) = @_;
251 251
252 my $delay_cb = sub { 252 # we _always_ delay kil's, to avoid calling mon callbacks
253 delete $AnyEvent::MP::Kernel::PORT{$port}; 253 # from anything but the event loop context.
254 delete $AnyEvent::MP::Kernel::PORT_DATA{$port}; 254 $DELAY = 1;
255 255 push @DELAY, sub { AnyEvent::MP::Kernel::_kill (@args) };
256 my $mon = delete $AnyEvent::MP::Kernel::LMON{$port} 256 $DELAY_W ||= AE::timer 0, 0, \&_send_delayed;
257 or !@reason
258 or $AnyEvent::MP::Kernel::WARN->(8, "unmonitored local port $port died with reason: @reason");
259
260 $_->(@reason) for values %$mon;
261 };
262
263 $DELAY_W ? push @DELAY, $delay_cb : &$delay_cb;
264} 257}
265 258
266sub monitor { 259sub monitor {
267 my ($self, $portid, $cb) = @_; 260 # shortcut
268 261 if ($DELAY_W) {
269 my $delay_cb = sub { 262 my @args = @_;
270 return $cb->(no_such_port => "cannot monitor nonexistent port", "$self->{id}#$portid") 263 push @DELAY, sub { AnyEvent::MP::Kernel::_monitor (@args) };
271 unless exists $AnyEvent::MP::Kernel::PORT{$portid}; 264 return;
272
273 $AnyEvent::MP::Kernel::LMON{$portid}{$cb+0} = $cb;
274 }; 265 }
275 266 &AnyEvent::MP::Kernel::_monitor;
276 $DELAY_W ? push @DELAY, $delay_cb : &$delay_cb;
277} 267}
278 268
279sub unmonitor { 269sub unmonitor {
280 my ($self, $portid, $cb) = @_; 270 if ($DELAY_W) {
281 271 my @args = @_;
282 my $delay_cb = sub { 272 push @DELAY, sub { AnyEvent::MP::Kernel::_unmonitor (@args) };
283 delete $AnyEvent::MP::Kernel::LMON{$portid}{$cb+0}; 273 return;
284 }; 274 }
285 275
286 $DELAY_W ? push @DELAY, $delay_cb : &$delay_cb; 276 &AnyEvent::MP::Kernel::_unmonitor;
287} 277}
288 278
289=head1 SEE ALSO 279=head1 SEE ALSO
290 280
291L<AnyEvent::MP>. 281L<AnyEvent::MP>.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines