Skip to content

Commit

Permalink
Merge pull request #643 from kraih/fix_fork
Browse files Browse the repository at this point in the history
fix forking while iterating over file handles with events, specifically using $_
  • Loading branch information
kraih committed Jul 6, 2014
2 parents d9aaa88 + cedeab3 commit 0779e1a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/Mojo/Reactor/Poll.pm
Expand Up @@ -42,13 +42,13 @@ sub one_tick {
# I/O
if (keys %{$self->{io}}) {
$poll->poll($timeout);
for my $f ($poll->handles(POLLIN | POLLPRI | POLLHUP | POLLERR)) {
next unless exists $self->{io}{fileno $f};
++$i and $self->_sandbox('Read', $self->{io}{fileno $f}{cb}, 0);
for my $handle ($poll->handles(POLLIN | POLLPRI | POLLHUP | POLLERR)) {
next unless my $io = $self->{io}{fileno $handle};
++$i and $self->_sandbox('Read', $io->{cb}, 0);
}
for my $f ($poll->handles(POLLOUT)) {
next unless exists $self->{io}{fileno $f};
++$i and $self->_sandbox('Write', $self->{io}{fileno $f}{cb}, 1);
for my $handle ($poll->handles(POLLOUT)) {
next unless my $io = $self->{io}{fileno $handle};
++$i and $self->_sandbox('Write', $io->{cb}, 1);
}
}

Expand Down
7 changes: 7 additions & 0 deletions t/mojo/reactor_ev.t
Expand Up @@ -150,6 +150,13 @@ ok !$recurring, 'recurring was not triggered again';
my $reactor2 = Mojo::Reactor::EV->new;
is ref $reactor2, 'Mojo::Reactor::Poll', 'right object';

# Reset while watchers are active
$writable = undef;
$reactor->io($_ => sub { ++$writable and shift->reset })->watch($_, 0, 1)
for $client, $server;
$reactor->start;
is $writable, 1, 'only one handle was writable';

# Concurrent reactors
$timer = 0;
$reactor->recurring(0 => sub { $timer++ });
Expand Down
7 changes: 7 additions & 0 deletions t/mojo/reactor_poll.t
Expand Up @@ -148,6 +148,13 @@ ok !$recurring, 'recurring was not triggered again';
my $reactor2 = Mojo::Reactor::Poll->new;
is ref $reactor2, 'Mojo::Reactor::Poll', 'right object';

# Reset while watchers are active
$writable = undef;
$reactor->io($_ => sub { ++$writable and shift->reset })->watch($_, 0, 1)
for $client, $server;
$reactor->start;
is $writable, 1, 'only one handle was writable';

# Concurrent reactors
$timer = 0;
$reactor->recurring(0 => sub { $timer++ });
Expand Down

0 comments on commit 0779e1a

Please sign in to comment.