File Coverage

blib/lib/MHFS/EventLoop/Poll/Linux.pm
Criterion Covered Total %
statement 15 17 88.2
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 21 23 91.3


line stmt bran cond sub pod time code
1             package MHFS::EventLoop::Poll::Linux v0.7.0;
2 1     1   594 use 5.014;
  1         4  
3 1     1   7 use strict; use warnings;
  1     1   2  
  1         35  
  1         4  
  1         2  
  1         63  
4 1     1   23 use feature 'say';
  1         2  
  1         140  
5 1     1   6 use parent 'MHFS::EventLoop::Poll::Base';
  1         2  
  1         8  
6 1     1   720 use MHFS::EventLoop::Poll::Linux::Timer;
  0            
  0            
7             sub new {
8             my $class = shift;
9             my $self = $class->SUPER::new(@_);
10             $self->{'evp_timer'} = MHFS::EventLoop::Poll::Linux::Timer->new($self);
11             return $self;
12             };
13              
14             sub add_timer {
15             my ($self, $start) = @_;
16             shift @_;
17             if($self->SUPER::add_timer(@_) == 0) {
18             say __PACKAGE__.": add_timer, updating linux timer to $start";
19             $self->{'evp_timer'}->settime_linux($start, 0);
20             }
21             };
22              
23             sub requeue_timers {
24             my $self = shift @_;
25             $self->SUPER::requeue_timers(@_);
26             my ($timers, $current_time) = @_;
27             if(@{$self->{'timers'}}) {
28             my $start = $self->{'timers'}[0]{'desired'} - $current_time;
29             say __PACKAGE__.": requeue_timers, updating linux timer to $start";
30             $self->{'evp_timer'}->settime_linux($start, 0);
31             }
32             };
33              
34             sub run {
35             my ($self, $loop_interval) = @_;
36             $loop_interval //= -1;
37             my $poll = $self->{'poll'};
38             for(;;)
39             {
40             print __PACKAGE__.": do_poll LINUX_X86_64 $$";
41             if($self->{'timers'}) {
42             say " timers " . scalar(@{$self->{'timers'}}) . ' handles ' . scalar($self->{'poll'}->handles());
43             }
44             else {
45             print "\n";
46             }
47              
48             $self->SUPER::do_poll($loop_interval, $poll);
49             }
50             };
51              
52             1;