Skip to content

Commit

Permalink
handle modes consistently in reactors
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 12, 2014
1 parent 853412c commit 634c68c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 9 additions & 9 deletions lib/Mojo/Reactor/EV.pm
Expand Up @@ -30,15 +30,15 @@ sub timer { shift->_timer(0, @_) }
sub watch {
my ($self, $handle, $read, $write) = @_;

my $mode = 0;
$mode |= EV::READ if $read;
$mode |= EV::WRITE if $write;

my $fd = fileno $handle;
my $io = $self->{io}{$fd};
my $mode;
if ($read && $write) { $mode = EV::READ | EV::WRITE }
elsif ($read) { $mode = EV::READ }
elsif ($write) { $mode = EV::WRITE }
else { delete $io->{watcher} }
if (my $w = $io->{watcher}) { $w->set($fd, $mode) }
elsif ($mode) {
if ($mode == 0) { delete $io->{watcher} }
elsif (my $w = $io->{watcher}) { $w->set($fd, $mode) }
else {
weaken $self;
$io->{watcher} = EV::io($fd, $mode, sub { $self->_io($fd, @_) });
}
Expand All @@ -49,9 +49,9 @@ sub watch {
sub _io {
my ($self, $fd, $w, $revents) = @_;
my $io = $self->{io}{$fd};
$self->_sandbox('Read', $io->{cb}, 0) if EV::READ &$revents;
$self->_sandbox('Read', $io->{cb}, 0) if EV::READ & $revents;
$self->_sandbox('Write', $io->{cb}, 1)
if EV::WRITE &$revents && $self->{io}{$fd};
if EV::WRITE & $revents && $self->{io}{$fd};
}

sub _timer {
Expand Down
8 changes: 5 additions & 3 deletions lib/Mojo/Reactor/Poll.pm
Expand Up @@ -99,11 +99,13 @@ sub timer { shift->_timer(0, @_) }
sub watch {
my ($self, $handle, $read, $write) = @_;

my $mode = 0;
$mode |= POLLIN | POLLPRI if $read;
$mode |= POLLOUT if $write;

my $poll = $self->_poll;
$poll->remove($handle);
if ($read && $write) { $poll->mask($handle, POLLIN | POLLPRI | POLLOUT) }
elsif ($read) { $poll->mask($handle, POLLIN | POLLPRI) }
elsif ($write) { $poll->mask($handle, POLLOUT) }
$poll->mask($handle, $mode) if $mode != 0;

return $self;
}
Expand Down

0 comments on commit 634c68c

Please sign in to comment.