blib/lib/Future/IO/Impl/Uring.pm

filter: Statementstmt 45.9% 68 / 148 Branchbran 7.5% 3 / 40 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 47.7% 21 / 44 Podpod 80.0% 8 / 10 totaltotal 41.1% 102 / 248 CC 22 SCAR 17.6
CC
22
Cov
38%
__ANON__
20.0
__ANON__
20.0
__ANON__
12.0
CRAP 5.8
↑ Summary
1 package Future::IO::Impl::Uring;
2 12 $Future::IO::Impl::Uring::VERSION = '0.010';
3 12 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 ▶use parent 'Future::IO::ImplBase';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 __PACKAGE__->APPLY;
9  
10 12 ▶use Future::IO 0.19 qw/POLLIN POLLOUT/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use IO::Uring 0.011 qw/IORING_TIMEOUT_ABS IORING_TIMEOUT_REALTIME IORING_TIMEOUT_ETIME_SUCCESS P_PID P_PGID P_ALL WEXITED/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use IO::Uring::Singleton 'ring';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 ▶use Errno 'ETIME';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 12 ▶use Signal::Info qw/CLD_EXITED/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 12 ▶use Time::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 12 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 sub _ring;
20 0 ▶*_ring = defined &Future::Uring::ring ? \&Future::Uring::ring : sub { state $ring = IO::Uring->new(128) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
defined &Future::Uring::ring ? : 0 12 12
21  
22 1 ▶sub accept($self, $fh) {
Subroutine accept: called CC=1 SCAR=3.8
Pod documented
23 1 my $future = Future::IO::Impl::Uring::_Future->new;
24 1 my $class = ref $fh;
25 0 ▶ my $id = ring->accept($fh, 0, sub($res, $flags) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
26 0 ▶ if ($res >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res >= 0) { } 0 0 0
27 0 my $accepted_fd = $class->new_from_fd($res, 'r+');
28 0 $future->done($accepted_fd);
29 } else {
30 0 local $! = -$res;
31 0 $future->fail("Accept: $!\n", accept => $fh, $!)
32 }
33 1 });
34 0 ▶ $future->on_cancel(sub { ring->cancel($id, 0, 0) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 0 return $future;
36 }
37  
38 0 ▶sub alarm($self, $seconds) {
Subroutine alarm: not called CC=1 SCAR=6.9
Pod documented
39 0 my $future = Future::IO::Impl::Uring::_Future->new;
40 0 my $time_spec = Time::Spec->new($seconds);
41 0 ▶ my $id = ring->timeout($time_spec, 0, IORING_TIMEOUT_REALTIME | IORING_TIMEOUT_ABS, 0, sub($res, $flags) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
42 0 ▶ if ($res != -ETIME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res != -62) { } 0 0 0
43 0 local $! = -$res;
44 0 $future->fail("alarm: $!\n");
45 } else {
46 0 $future->done;
47 }
48 0 });
49 0 ▶ $future->on_cancel(sub { ring->cancel($id, 0, 0) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 return $future;
51 }
52  
53 1 ▶sub connect($self, $fh, $name) {
Subroutine connect: called CC=1 SCAR=4.4
Pod documented
54 1 my $future = Future::IO::Impl::Uring::_Future->new;
55 0 ▶ my $id = ring->connect($fh, $name, 0, sub($res, $flags) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
56 0 ▶ if ($res < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res < 0) { } 0 0 0
57 0 local $! = -$res;
58 0 $future->fail("connect: $!\n", connect => $fh, $!);
59 } else {
60 0 $future->done;
61 }
62 1 });
63 0 ▶ $future->on_cancel(sub { ring->cancel($id, 0, 0) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 return $future;
65 }
66  
67 1 ▶sub poll($self, $fh, $mask) {
Subroutine poll: called CC=1 SCAR=4.4
Pod undocumented
68 1 my $future = Future::IO::Impl::Uring::_Future->new;
69 0 ▶ my $id = ring->poll($fh, $mask, 0, sub($res, $flags) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
70 0 ▶ if ($res >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res >= 0) { } 0 0 0
71 0 $future->done($res);
72 } else {
73 0 local $! = -$res;
74 0 $future->fail("poll: $!\n", poll => $fh, $!);
75 }
76 1 });
77 0 ▶ $future->on_cancel(sub { ring->cancel($id, 0, 0) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 0 return $future;
79 }
80  
81 1 ▶sub recv($self, $fh, $length, $flags) {
Subroutine recv: called CC=2 SCAR=13.0
Pod documented
82 1 my $future = Future::IO::Impl::Uring::_Future->new;
83 1 my $buffer = "\0" x $length;
84 1 ▶ $flags //= 0;
Condition50%1/2
$flags //= 0
l!l
01
MC/DC0%0/1
$flags //= 0
$flags
Truth table50%1/2
A
A= $flags
Aresult
11
00
85 0 ▶ my $id = ring->recv($fh, $buffer, $flags, 0, 0, sub($res, $flags) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
86 0 ▶ if ($res > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($res > 0) { } 0 0 0
elsif ($res == 0) { } 0 0 0
87 0 ▶ $future->done($res == $length ? $buffer : substr $buffer, 0, $res);
Branch: 1 branch
BranchTrueFalseTotal
$res == $length ? : 0 0 0
88 } elsif ($res == 0) {
89 0 $future->done;
90 } else {
91 0 local $! = -$res;
92 0 $future->fail("recv: $!\n", recv => $fh, $!);
93 }
94 1 });
95 0 ▶ $future->on_cancel(sub { ring->cancel($id, 0, 0) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
96 0 return $future;
97 }
98  
99 1 ▶sub send($self, $fh, $buffer, $flags, $to) {
Subroutine send: called CC=3 SCAR=16.0
Pod documented
100 1 my $future = Future::IO::Impl::Uring::_Future->new;
101 0 ▶ my $callback = sub($res, $flags) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
102 0 ▶ if ($res >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res >= 0) { } 0 0 0
103 0 $future->done($res);
104 } else {
105 0 local $! = -$res;
106 0 $future->fail("send: $!\n", send => $fh, $!);
107 }
108 1 };
109 1 ▶ $flags //= 0;
Condition50%1/2
$flags //= 0
l!l
10
MC/DC0%0/1
$flags //= 0
$flags
Truth table50%1/2
A
A= $flags
Aresult
11
00
110 1 my $id;
111 1 ▶ if (defined $to) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $to) { } 1 0 1
112 1 $id = ring->sendto($fh, $buffer, $flags, $to, 0, 0, $callback);
113 } else {
114 0 $id = ring->send($fh, $buffer, $flags, 0, 0, $callback);
115 }
116 0 ▶ $future->on_cancel(sub { ring->cancel($id, 0, 0) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
117 0 return $future;
118 }
119  
120 1 ▶sub sleep($self, $seconds) {
Subroutine sleep: called CC=1 SCAR=3.5
Pod documented
121 1 my $future = Future::IO::Impl::Uring::_Future->new;
122 1 my $time_spec = Time::Spec->new($seconds);
123 0 ▶ my $id = ring->timeout($time_spec, 0, 0, 0, sub($res, $flags) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
124 0 ▶ if ($res != -ETIME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res != -62) { } 0 0 0
125 0 local $! = -$res;
126 0 $future->fail("sleep: $!\n");
127 } else {
128 0 $future->done;
129 }
130 1 });
131 0 ▶ $future->on_cancel(sub { ring->cancel($id, 0, 0) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
132 0 return $future;
133 }
134  
135 1 ▶sub sysread($self, $fh, $length) {
Subroutine sysread: called CC=1 SCAR=4.4
Pod documented
136 1 my $future = Future::IO::Impl::Uring::_Future->new;
137 1 my $buffer = "\0" x $length;
138 0 ▶ my $id = ring->read($fh, $buffer, -1, 0, sub($res, $flags) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
139 0 ▶ if ($res > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($res > 0) { } 0 0 0
elsif ($res == 0) { } 0 0 0
140 0 ▶ $future->done($res == $length ? $buffer : substr $buffer, 0, $res);
Branch: 1 branch
BranchTrueFalseTotal
$res == $length ? : 0 0 0
141 } elsif ($res == 0) {
142 0 $future->done;
143 } else {
144 0 local $! = -$res;
145 0 $future->fail("sysread: $!\n", sysread => $fh, $!);
146 }
147 1 });
148 0 ▶ $future->on_cancel(sub { ring->cancel($id, 0, 0) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
149 0 return $future;
150 }
151  
152 1 ▶sub syswrite($self, $fh, $buffer) {
Subroutine syswrite: called CC=1 SCAR=4.4
Pod documented
153 1 my $future = Future::IO::Impl::Uring::_Future->new;
154 0 ▶ my $id = ring->write($fh, $buffer, -1, 0, sub($res, $flags) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
155 0 ▶ if ($res >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res >= 0) { } 0 0 0
156 0 $future->done($res);
157 } else {
158 0 local $! = -$res;
159 0 $future->fail("syswrite: $!\n", syswrite => $fh, $!);
160 }
161 1 });
162 0 ▶ $future->on_cancel(sub { ring->cancel($id, 0, 0) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
163 0 return $future;
164 }
165  
166 1 ▶sub waitpid($self, $pid) {
Subroutine waitpid: called CC=3 SCAR=18.9
Pod undocumented
167 1 my $future = Future::IO::Impl::Uring::_Future->new;
168 1 my $info = Signal::Info->new;
169 1 ▶ my ($type, $arg) = $pid > 0 ? (P_PID, $pid) : $pid < 0 ? (P_PGID, -$pid) : (P_ALL, 0);
Branch: 2 branches
BranchTrueFalseTotal
$pid > 0 ? : 1 0 1
$pid < 0 ? : 0 0 0
170 0 ▶ my $id = ring->waitid($type, $arg, $info, WEXITED, 0, 0, sub($res, $flags) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
171 0 ▶ if ($res >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res >= 0) { } 0 0 0
172 0 ▶ $future->done($info->code == CLD_EXITED ? ($info->status << 8) : $info->status);
Branch: 1 branch
BranchTrueFalseTotal
$info->code == 1 ? : 0 0 0
173 } else {
174 0 local $! = -$res;
175 0 $future->fail("waitpid: $!\n", waitpid => $pid, $!);
176 }
177 1 });
178 0 ▶ $future->on_cancel(sub { ring->cancel($id, 0, 0) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
179 0 return $future;
180 }
181  
182 package
183 Future::IO::Impl::Uring::_Future;
184  
185 12 ▶use parent 'Future';
Subroutine BEGIN: called CC=1 SCAR=0.0
186  
187 0 ▶sub await($self) {
Subroutine await: not called CC=2 SCAR=17.9
188 0 ▶ IO::Uring::Singleton::ring->run_once until $self->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_ready or do { IO::Uring::Singleton::ring()->run_once } 0 0 0
189 0 return $self;
190 }
191  
192 12 1;
193  
194 # ABSTRACT: A Future::IO implementation for IO::Uring
195  
196 __END__
↑ Summary