Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use IO::Poll consistently
  • Loading branch information
kraih committed Feb 23, 2015
1 parent f7eca60 commit 2053bf2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Reactor.pm
Expand Up @@ -16,7 +16,7 @@ sub io { croak 'Method "io" not implemented by subclass' }

# This may break in the future, but is worth it for performance
sub is_readable {
!(IO::Poll::_poll(0, fileno(pop), my $dummy = POLLIN | POLLPRI) == 0);
!!(IO::Poll::_poll(0, fileno(pop), my $mode = POLLIN | POLLPRI) > 0);
}

sub is_running { croak 'Method "is_running" not implemented by subclass' }
Expand Down
14 changes: 6 additions & 8 deletions lib/Mojo/Server/Prefork.pm
Expand Up @@ -88,8 +88,6 @@ sub run {

# Pipe for worker communication
pipe($self->{reader}, $self->{writer}) or die "Can't create pipe: $!";
$self->{poll} = IO::Poll->new;
$self->{poll}->mask($self->{reader}, POLLIN | POLLPRI);

# Clean manager environment
local $SIG{CHLD} = sub {
Expand Down Expand Up @@ -181,7 +179,7 @@ sub _spawn {
# Clean worker environment
$SIG{$_} = 'DEFAULT' for qw(CHLD INT TERM TTIN TTOU);
$SIG{QUIT} = sub { $loop->stop_gracefully };
delete @$self{qw(poll reader)};
delete $self->{reader};
srand;

$self->app->log->debug("Worker $$ started");
Expand All @@ -208,11 +206,11 @@ sub _term {
sub _wait {
my $self = shift;

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

# Update heartbeats (and stop gracefully if necessary)
my $time = steady_time;
Expand Down
6 changes: 1 addition & 5 deletions lib/Mojo/Upload.pm
Expand Up @@ -8,11 +8,7 @@ has asset => sub { Mojo::Asset::File->new };
has [qw(filename name)];
has headers => sub { Mojo::Headers->new };

sub move_to {
my $self = shift;
$self->asset->move_to(@_);
return $self;
}
sub move_to { $_[0]->asset->move_to($_[1]) and return $_[0] }

sub size { shift->asset->size }
sub slurp { shift->asset->slurp }
Expand Down

0 comments on commit 2053bf2

Please sign in to comment.