Skip to content

Commit

Permalink
Mojo::Reactor::is_readable is not needed anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 23, 2015
1 parent 2053bf2 commit 83a05c9
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 21 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

5.82 2015-02-22
- Deprecated Mojo::Reactor::is_readable.
- Deprecated keep_alive_requests setting in Hypnotoad in favor of requests.
- Improved Morbo to restart slightly faster.
- Fixed bug in daemon and prefork commands where --inactivity-timeout option
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/IOLoop/Stream.pm
Expand Up @@ -25,7 +25,7 @@ sub handle { shift->{handle} }
sub is_readable {
my $self = shift;
$self->_again;
return $self->{handle} && $self->reactor->is_readable($self->{handle});
return $self->{handle} && Mojo::Util::_readable(0, fileno $self->{handle});
}

sub is_writing {
Expand Down
14 changes: 4 additions & 10 deletions lib/Mojo/Reactor.pm
Expand Up @@ -2,8 +2,8 @@ package Mojo::Reactor;
use Mojo::Base 'Mojo::EventEmitter';

use Carp 'croak';
use IO::Poll qw(POLLIN POLLPRI);
use Mojo::Loader 'load_class';
use Mojo::Util 'deprecated';

sub again { croak 'Method "again" not implemented by subclass' }

Expand All @@ -14,9 +14,10 @@ sub detect {

sub io { croak 'Method "io" not implemented by subclass' }

# This may break in the future, but is worth it for performance
# DEPRECATED in Tiger Face!
sub is_readable {
!!(IO::Poll::_poll(0, fileno(pop), my $mode = POLLIN | POLLPRI) > 0);
deprecated 'Mojo::Reactor::is_readable is DEPRECATED';
Mojo::Util::_readable(0, fileno pop);
}

sub is_running { croak 'Method "is_running" not implemented by subclass' }
Expand Down Expand Up @@ -119,13 +120,6 @@ readable or writable. Meant to be overloaded in a subclass.
say $writable ? 'Handle is writable' : 'Handle is readable';
});
=head2 is_readable
my $bool = $reactor->is_readable($handle);
Quick non-blocking check if a handle is readable, useful for identifying
tainted sockets.
=head2 is_running
my $bool = $reactor->is_running;
Expand Down
6 changes: 2 additions & 4 deletions lib/Mojo/Server/Prefork.pm
Expand Up @@ -2,7 +2,6 @@ package Mojo::Server::Prefork;
use Mojo::Base 'Mojo::Server::Daemon';

use File::Spec::Functions qw(catfile tmpdir);
use IO::Poll qw(POLLIN POLLPRI);
use Mojo::Util qw(deprecated steady_time);
use POSIX 'WNOHANG';
use Scalar::Util 'weaken';
Expand Down Expand Up @@ -206,10 +205,9 @@ sub _term {
sub _wait {
my $self = shift;

# This may break in the future, but is worth it for performance
# Poll for heartbeats
my $reader = $self->emit('wait')->{reader};
my $mode = POLLIN | POLLPRI;
return unless IO::Poll::_poll(1000, fileno($reader), $mode) > 0;
return unless Mojo::Util::_readable(1000, fileno($reader));
return unless $reader->sysread(my $chunk, 4194304);

# Update heartbeats (and stop gracefully if necessary)
Expand Down
4 changes: 4 additions & 0 deletions lib/Mojo/Util.pm
Expand Up @@ -7,6 +7,7 @@ use Digest::MD5 qw(md5 md5_hex);
use Digest::SHA qw(hmac_sha1_hex sha1 sha1_hex);
use Encode 'find_encoding';
use Exporter 'import';
use IO::Poll qw(POLLIN POLLPRI);
use List::Util 'min';
use MIME::Base64 qw(decode_base64 encode_base64);
use Symbol 'delete_package';
Expand Down Expand Up @@ -426,6 +427,9 @@ sub _options {
return ref $_[1] eq 'HASH' ? (shift, %{shift()}) : (undef, @_);
}

# This may break in the future, but is worth it for performance
sub _readable { !!(IO::Poll::_poll(@_[0, 1], my $m = POLLIN | POLLPRI) > 0) }

sub _stash {
my ($name, $object) = (shift, shift);

Expand Down
2 changes: 0 additions & 2 deletions t/mojo/reactor_ev.t
Expand Up @@ -39,15 +39,13 @@ $reactor->timer(0.025 => sub { shift->stop });
$reactor->start;
ok !$readable, 'handle is not readable';
ok !$writable, 'handle is not writable';
ok !$reactor->is_readable($listen), 'handle is not readable';

# Connect
my $client = IO::Socket::INET->new(PeerAddr => '127.0.0.1', PeerPort => $port);
$reactor->timer(1 => sub { shift->stop });
$reactor->start;
ok $readable, 'handle is readable';
ok !$writable, 'handle is not writable';
ok $reactor->is_readable($listen), 'handle is readable';

# Accept
my $server = $listen->accept;
Expand Down
2 changes: 0 additions & 2 deletions t/mojo/reactor_poll.t
Expand Up @@ -36,15 +36,13 @@ $reactor->timer(0.025 => sub { shift->stop });
$reactor->start;
ok !$readable, 'handle is not readable';
ok !$writable, 'handle is not writable';
ok !$reactor->is_readable($listen), 'handle is not readable';

# Connect
my $client = IO::Socket::INET->new(PeerAddr => '127.0.0.1', PeerPort => $port);
$reactor->timer(1 => sub { shift->stop });
$reactor->start;
ok $readable, 'handle is readable';
ok !$writable, 'handle is not writable';
ok $reactor->is_readable($listen), 'handle is readable';

# Accept
my $server = $listen->accept;
Expand Down
4 changes: 2 additions & 2 deletions t/pod_coverage.t
Expand Up @@ -9,8 +9,8 @@ plan skip_all => 'Test::Pod::Coverage 1.04+ required for this test!'

# DEPRECATED in Tiger Face!
my @tiger = (
qw(accept_interval bridge data is_binary load lock lock_file lock_timeout),
qw(max_connections new search siblings unlock)
qw(accept_interval bridge data is_binary is_readable load lock lock_file),
qw(lock_timeout max_connections new search siblings unlock)
);

all_pod_coverage_ok({also_private => [@tiger]});

0 comments on commit 83a05c9

Please sign in to comment.