| 1 | # $Id: Select.pm,v 1.18 2010/01/01 14:52:17 dk Exp $ | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package IO::Lambda::Loop::Select; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 28 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 28 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 28 | ▶ | use Errno qw(EINTR EAGAIN); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 28 | ▶ | use IO::Lambda qw(:constants); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 28 | ▶ | use Time::HiRes qw(time); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 28 | IO::Lambda::Loop::default('Select'); | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 28 | ▶ | our $DEBUG = $IO::Lambda::DEBUG{select} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$IO::Lambda::DEBUG{'select'} || 0
MC/DC0%0/1
$IO::Lambda::DEBUG{'select'} || 0
$IO::Lambda::DEBUG{'select'}
Truth table50%1/2
A
A= $IO::Lambda::DEBUG{'select'}
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | # IO::Select::select doesn't distinguish between select returning 0 and -1, don't have | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # time to fix that. I'll just use a plain select instead, it'll be faster also. | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 18 | { | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 27 | ▶ | my $self = bless {} , shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 27 | $self-> {$_} = '' for qw(read write exc); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 27 | $self-> {items} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 27 | $self-> {timers} = []; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 27 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | sub empty | ||||||||||||||||||||||||||||||||||||||||||
| 27 | { | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 867555 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
empty: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 867555 | @{$self->{timers}} + | |||||||||||||||||||||||||||||||||||||||||
| 31 | 867555 | ▶ | keys(%{$self-> {items}}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | ) ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | sub yield | ||||||||||||||||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 178 | ▶ | my ( $self, $nonblocking ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
yield: called CC=42 SCAR=42.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 178 | ▶ | return if $self-> empty; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 178 | my $t; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 178 | ▶ | $t = 0 if $nonblocking; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 178 | my ($min,$max) = ( 0, -1); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 178 | my $ct = time; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # timers | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 178 | for ( @{$self-> {timers}}) { | |||||||||||||||||||||||||||||||||||||||||
| 49 | 132 | ▶ | $t = $_->[WATCH_DEADLINE] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $_->[2] and !defined($t) || $t > $_->[2]
not defined $t or $t > $_->[2]
MC/DC33%1/3
defined $_->[2] and !defined($t) || $t > $_->[2]
defined $_->[2]
not defined $t
$t > $_->[2]
Truth table50%2/4
A and not(B) or C
A= defined $_->[2]B= not defined $tC= $t > $_->[2]
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | if defined $_->[WATCH_DEADLINE] and | ||||||||||||||||||||||||||||||||||||||||||
| 51 | (!defined($t) or $t > $_-> [WATCH_DEADLINE]); | ||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # handles | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 178 | my ( $R, $W, $E) = @{$self}{qw(read write exc)}; | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 178 | ▶ | while ( my ( $fileno, $bucket) = each %{ $self-> {items}} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 160 | for ( @$bucket) { | |||||||||||||||||||||||||||||||||||||||||
| 59 | 160 | ▶ | $t = $_->[WATCH_DEADLINE] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $_->[2] and !defined($t) || $t > $_->[2]
not defined $t or $t > $_->[2]
MC/DC66%2/3
defined $_->[2] and !defined($t) || $t > $_->[2]
defined $_->[2]
not defined $t
$t > $_->[2]
Truth table75%3/4
A and not(B) or C
A= defined $_->[2]B= not defined $tC= $t > $_->[2]
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | if defined $_->[WATCH_DEADLINE] and | ||||||||||||||||||||||||||||||||||||||||||
| 61 | (!defined($t) or $t > $_-> [WATCH_DEADLINE]); | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 160 | ▶ | warn "select: fileno $fileno\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 160 | ▶ | $max = $fileno if $max < $fileno; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 160 | ▶ | $min = $fileno if !defined($min) or $min > $fileno; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $min or $min > $fileno
MC/DC0%0/2
not defined $min or $min > $fileno
not defined $min
$min > $fileno
Truth table33%1/3
not(A) or B
A= not defined $minB= $min > $fileno
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 178 | ▶ | if ( defined $t) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 108 | $t -= $ct; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 108 | ▶ | $t = 0 if $t < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 108 | ▶ | warn "select: timeout=$t\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | } elsif ( $DEBUG) { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | warn "select: no timeout\n"; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # do select | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 178 | my $n = select( $R, $W, $E, $t); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 178 | ▶ | warn "select: $n handles ready\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 178 | ▶ | if ( $n < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | if ( $! == EINTR or $! == EAGAIN) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$! == 4 or $! == 11
MC/DC0%0/2
$! == 4 or $! == 11
$! == 4
$! == 11
Truth table33%1/3
A or B
A= $! == 4B= $! == 11
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | # ignore | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | warn "select: $!\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # find out the rogue handles | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ( $DEBUG > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $h = $R | $W | $E; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | for ( my $i = 0; $i < length($h); $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $v = ''; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | for ( my $j = 0; $j < 8; $j++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $fd = $i * 8 + $j; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | next unless vec($h,$fd,1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | vec($v,$fd,1) = 1; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | next if select($v,$v,$v,0) >= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | warn "select: bad handle #$fd\n"; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | die "select() error:$!:$^E"; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | # expired timers | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 178 | my ( @kill, @expired); | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 178 | $t = $self-> {timers}; | |||||||||||||||||||||||||||||||||||||||||
| 105 | @$t = grep { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 178 | ▶ | ($$_[WATCH_DEADLINE] <= $ct) ? do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 47 | push @expired, $_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 47 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } : 1; | ||||||||||||||||||||||||||||||||||||||||||
| 110 | } @$t; | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | # handles | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 178 | ▶ | if ( $n > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | # process selected handles | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 95 | ▶ | for ( my $i = $min; $i <= $max && $n > 0; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i <= $max and $n > 0
MC/DC100%2/2
$i <= $max and $n > 0
$i <= $max
$n > 0
Truth table100%3/3
A and B
A= $i <= $maxB= $n > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 1179 | my $what = | |||||||||||||||||||||||||||||||||||||||||
| 117 | vec( $R, $i, 1) * IO_READ + | ||||||||||||||||||||||||||||||||||||||||||
| 118 | vec( $W, $i, 1) * IO_WRITE + | ||||||||||||||||||||||||||||||||||||||||||
| 119 | vec( $E, $i, 1) * IO_EXCEPTION | ||||||||||||||||||||||||||||||||||||||||||
| 120 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 1179 | ▶ | next unless $what; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 120 | my $bucket = $self-> {items}-> {$i}; | |||||||||||||||||||||||||||||||||||||||||
| 124 | @$bucket = grep { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 120 | ▶ | ($$_[WATCH_IO_FLAGS] & $what) ? do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 120 | $$_[WATCH_IO_FLAGS] &= $what; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 120 | push @expired, $_; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 120 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } : 1; | ||||||||||||||||||||||||||||||||||||||||||
| 130 | } @$bucket; | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 120 | ▶ | delete $self-> {items}->{$i} unless @$bucket; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 120 | $n--; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # else process timeouts | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 83 | my @kill; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 83 | ▶ | while ( my ( $fileno, $bucket) = each %{ $self-> {items}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | @$bucket = grep { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 8 | ( | |||||||||||||||||||||||||||||||||||||||||
| 140 | defined($_->[WATCH_DEADLINE]) && | ||||||||||||||||||||||||||||||||||||||||||
| 141 | $_->[WATCH_DEADLINE] <= $ct | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 8 | ▶ | ) ? do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $_->[2] and $_->[2] <= $ct
MC/DC100%2/2
defined $_->[2] and $_->[2] <= $ct
defined $_->[2]
$_->[2] <= $ct
Truth table100%3/3
A and B
A= defined $_->[2]B= $_->[2] <= $ct
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | $$_[WATCH_IO_FLAGS] = 0; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | push @expired, $_; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } : 1; | ||||||||||||||||||||||||||||||||||||||||||
| 147 | } @$bucket; | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 8 | ▶ | push @kill, $fileno unless @$bucket; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 83 | delete @{$self->{items}}{@kill}; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 178 | $self-> rebuild_vectors; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | # call them | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 178 | $$_[WATCH_OBJ]-> io_handler( $_) for @expired; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | sub watch | ||||||||||||||||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 127 | ▶ | my ( $self, $rec) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
watch: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 127 | my $fileno = fileno $rec->[WATCH_IO_HANDLE]; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 127 | ▶ | die "Invalid filehandle" unless defined $fileno; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 127 | my $flags = $rec->[WATCH_IO_FLAGS]; | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 127 | ▶ | vec($self-> {read}, $fileno, 1) = 1 if $flags & IO_READ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 127 | ▶ | vec($self-> {write}, $fileno, 1) = 1 if $flags & IO_WRITE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 127 | ▶ | vec($self-> {exc}, $fileno, 1) = 1 if $flags & IO_EXCEPTION; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 127 | push @{$self-> {items}-> {$fileno}}, $rec; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | sub after | ||||||||||||||||||||||||||||||||||||||||||
| 173 | { | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 58 | ▶ | my ( $self, $rec) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
after: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 58 | push @{$self-> {timers}}, $rec; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | sub remove | ||||||||||||||||||||||||||||||||||||||||||
| 179 | { | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 46 | ▶ | my ($self, $obj) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 46 | @{$self-> {timers}} = grep { | |||||||||||||||||||||||||||||||||||||||||
| 183 | 7 | ▶ | defined($_->[WATCH_OBJ]) and $_->[WATCH_OBJ] != $obj | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 46 | } @{$self-> {timers}}; | |||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 46 | my @kill; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 46 | ▶ | while ( my ( $fileno, $bucket) = each %{$self->{items}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 27 | ▶ | @$bucket = grep { defined($_->[WATCH_OBJ]) and $_->[WATCH_OBJ] != $obj } @$bucket; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 27 | ▶ | next if @$bucket; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 5 | push @kill, $fileno; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 46 | delete @{$self->{items}}{@kill}; | |||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 46 | $self-> rebuild_vectors; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | sub remove_event | ||||||||||||||||||||||||||||||||||||||||||
| 198 | { | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 10 | ▶ | my ($self, $rec) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove_event: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 10 | @{$self-> {timers}} = grep { $_ != $rec } @{$self-> {timers}}; | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 10 | my @kill; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 10 | ▶ | while ( my ( $fileno, $bucket) = each %{$self->{items}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 2 | @$bucket = grep { $_ != $rec } @$bucket; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | ▶ | next if @$bucket; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | push @kill, $fileno; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 10 | delete @{$self->{items}}{@kill}; | |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 10 | $self-> rebuild_vectors; | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | sub rebuild_vectors | ||||||||||||||||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 234 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rebuild_vectors: called CC=7 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 234 | $self-> {$_} = '' for qw(read write exc); | |||||||||||||||||||||||||||||||||||||||||
| 219 | 234 | my $r = \ $self-> {read}; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 234 | my $w = \ $self-> {write}; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 234 | my $e = \ $self-> {exc}; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 234 | ▶ | while ( my ( $fileno, $bucket) = each %{$self->{items}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 63 | for my $flags ( map { $_-> [WATCH_IO_FLAGS] } @$bucket) { | |||||||||||||||||||||||||||||||||||||||||
| 224 | 63 | ▶ | vec($$r, $fileno, 1) = 1 if $flags & IO_READ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 63 | ▶ | vec($$w, $fileno, 1) = 1 if $flags & IO_WRITE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 63 | ▶ | vec($$e, $fileno, 1) = 1 if $flags & IO_EXCEPTION; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 28 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||