line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2021 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Test::Future::IO::Impl 0.13; |
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
1144849
|
use v5.14; |
|
6
|
|
|
|
|
50
|
|
9
|
6
|
|
|
6
|
|
34
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
150
|
|
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
30
|
use Test2::V0; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
34
|
|
12
|
6
|
|
|
6
|
|
7048
|
use Test2::API (); |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
122
|
|
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
6
|
|
2655
|
use Errno qw( EINVAL EPIPE ); |
|
6
|
|
|
|
|
6816
|
|
|
6
|
|
|
|
|
603
|
|
15
|
6
|
|
|
6
|
|
3484
|
use IO::Handle; |
|
6
|
|
|
|
|
37973
|
|
|
6
|
|
|
|
|
290
|
|
16
|
6
|
|
|
6
|
|
2979
|
use Socket qw( pack_sockaddr_in INADDR_LOOPBACK ); |
|
6
|
|
|
|
|
19678
|
|
|
6
|
|
|
|
|
913
|
|
17
|
6
|
|
|
6
|
|
46
|
use Time::HiRes qw( time ); |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
64
|
|
18
|
|
|
|
|
|
|
|
19
|
6
|
|
|
6
|
|
826
|
use Exporter 'import'; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
10447
|
|
20
|
|
|
|
|
|
|
our @EXPORT = qw( run_tests ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
C - acceptance tests for C implementations |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Test::More; |
29
|
|
|
|
|
|
|
use Test::Future::IO::Impl; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use Future::IO; |
32
|
|
|
|
|
|
|
use Future::IO::Impl::MyNewImpl; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
run_tests 'sleep'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
done_testing; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 DESCRIPTION |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
This module contains a collection of acceptance tests for implementations of |
41
|
|
|
|
|
|
|
L. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 FUNCTIONS |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $errstr_EPIPE = do { |
50
|
|
|
|
|
|
|
# On MSWin32 we don't get EPIPE, but EINVAL |
51
|
|
|
|
|
|
|
local $! = $^O eq "MSWin32" ? EINVAL : EPIPE; "$!"; |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $errstr_ECONNREFUSED = do { |
55
|
|
|
|
|
|
|
local $! = Errno::ECONNREFUSED; "$!"; |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub time_about(&@) |
59
|
|
|
|
|
|
|
{ |
60
|
3
|
|
|
3
|
0
|
14
|
my ( $code, $want_time, $name ) = @_; |
61
|
3
|
|
|
|
|
13
|
my $ctx = Test2::API::context; |
62
|
|
|
|
|
|
|
|
63
|
3
|
|
|
|
|
6111
|
my $t0 = time(); |
64
|
3
|
|
|
|
|
10
|
$code->(); |
65
|
3
|
|
|
|
|
93
|
my $t1 = time(); |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
12
|
my $got_time = $t1 - $t0; |
68
|
3
|
50
|
33
|
|
|
68
|
$ctx->ok( |
69
|
|
|
|
|
|
|
$got_time >= $want_time * 0.9 && $got_time <= $want_time * 1.5, $name |
70
|
|
|
|
|
|
|
) or |
71
|
|
|
|
|
|
|
$ctx->diag( sprintf "Test took %.3f seconds", $got_time ); |
72
|
|
|
|
|
|
|
|
73
|
3
|
|
|
|
|
970
|
$ctx->release; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 run_tests |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
run_tests @suitenames |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Runs a collection of tests against C. It is expected that the |
81
|
|
|
|
|
|
|
caller has already loaded the specific implementation module to be tested |
82
|
|
|
|
|
|
|
against before this function is called. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub run_tests |
87
|
|
|
|
|
|
|
{ |
88
|
5
|
|
|
5
|
1
|
475
|
foreach my $test ( @_ ) { |
89
|
5
|
50
|
|
|
|
101
|
my $code = __PACKAGE__->can( "run_${test}_test" ) |
90
|
|
|
|
|
|
|
or die "Unrecognised test suite name $test"; |
91
|
5
|
|
|
|
|
37
|
__PACKAGE__->$code(); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 TEST SUITES |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
The following test suite names may be passed to the L function: |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 accept |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Tests the C<< Future::IO->accept >> method. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub run_accept_test |
108
|
|
|
|
|
|
|
{ |
109
|
1
|
|
|
1
|
0
|
569
|
require IO::Socket::INET; |
110
|
|
|
|
|
|
|
|
111
|
1
|
50
|
|
|
|
9333
|
my $serversock = IO::Socket::INET->new( |
112
|
|
|
|
|
|
|
Type => Socket::SOCK_STREAM(), |
113
|
|
|
|
|
|
|
LocalAddr => "localhost", |
114
|
|
|
|
|
|
|
LocalPort => 0, |
115
|
|
|
|
|
|
|
Listen => 1, |
116
|
|
|
|
|
|
|
) or die "Cannot socket()/listen() - $@"; |
117
|
|
|
|
|
|
|
|
118
|
1
|
|
|
|
|
919
|
$serversock->blocking( 0 ); |
119
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
36
|
my $f = Future::IO->accept( $serversock ); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Some platforms have assigned 127.0.0.1 here; others have left 0.0.0.0 |
123
|
|
|
|
|
|
|
# If it's still 0.0.0.0, then guess that maybe connecting to 127.0.0.1 will |
124
|
|
|
|
|
|
|
# work |
125
|
1
|
50
|
|
|
|
177
|
my $sockname = ( $serversock->sockhost ne "0.0.0.0" ) |
126
|
|
|
|
|
|
|
? $serversock->sockname |
127
|
|
|
|
|
|
|
: pack_sockaddr_in( $serversock->sockport, INADDR_LOOPBACK ); |
128
|
|
|
|
|
|
|
|
129
|
1
|
50
|
|
|
|
78
|
my $clientsock = IO::Socket::INET->new( |
130
|
|
|
|
|
|
|
Type => Socket::SOCK_STREAM(), |
131
|
|
|
|
|
|
|
) or die "Cannot socket() - $@"; |
132
|
1
|
50
|
|
|
|
225
|
$clientsock->connect( $sockname ) or die "Cannot connect() - $@"; |
133
|
|
|
|
|
|
|
|
134
|
1
|
|
|
|
|
144
|
my $acceptedsock = $f->get; |
135
|
|
|
|
|
|
|
|
136
|
1
|
|
|
|
|
24
|
ok( $clientsock->peername eq $acceptedsock->sockname, 'Accepted socket address matches' ); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 connect |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Tests the C<< Future::IO->connect >> method. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub run_connect_test |
146
|
|
|
|
|
|
|
{ |
147
|
1
|
|
|
1
|
0
|
530
|
require IO::Socket::INET; |
148
|
|
|
|
|
|
|
|
149
|
1
|
50
|
|
|
|
9266
|
my $serversock = IO::Socket::INET->new( |
150
|
|
|
|
|
|
|
Type => Socket::SOCK_STREAM(), |
151
|
|
|
|
|
|
|
LocalAddr => "localhost", |
152
|
|
|
|
|
|
|
LocalPort => 0, |
153
|
|
|
|
|
|
|
Listen => 1, |
154
|
|
|
|
|
|
|
) or die "Cannot socket()/listen() - $@"; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# Some platforms have assigned 127.0.0.1 here; others have left 0.0.0.0 |
157
|
|
|
|
|
|
|
# If it's still 0.0.0.0, then guess that maybe connecting to 127.0.0.1 will |
158
|
|
|
|
|
|
|
# work |
159
|
1
|
50
|
|
|
|
963
|
my $sockname = ( $serversock->sockhost ne "0.0.0.0" ) |
160
|
|
|
|
|
|
|
? $serversock->sockname |
161
|
|
|
|
|
|
|
: pack_sockaddr_in( $serversock->sockport, INADDR_LOOPBACK ); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# ->connect success |
164
|
|
|
|
|
|
|
{ |
165
|
1
|
50
|
|
|
|
71
|
my $clientsock = IO::Socket::INET->new( |
|
1
|
|
|
|
|
8
|
|
166
|
|
|
|
|
|
|
Type => Socket::SOCK_STREAM(), |
167
|
|
|
|
|
|
|
) or die "Cannot socket() - $@"; |
168
|
1
|
|
|
|
|
197
|
$clientsock->blocking( 0 ); |
169
|
|
|
|
|
|
|
|
170
|
1
|
|
|
|
|
26
|
my $f = Future::IO->connect( $clientsock, $sockname ); |
171
|
|
|
|
|
|
|
|
172
|
1
|
|
|
|
|
140
|
$f->get; |
173
|
|
|
|
|
|
|
|
174
|
1
|
|
|
|
|
25
|
my $acceptedsock = $serversock->accept; |
175
|
1
|
|
|
|
|
174
|
ok( $clientsock->peername eq $acceptedsock->sockname, 'Accepted socket address matches' ); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
1
|
|
|
|
|
6892
|
$serversock->close; |
179
|
1
|
|
|
|
|
37
|
undef $serversock; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# I really hate this, but apparently Win32 testers will fail if we don't |
182
|
|
|
|
|
|
|
# do this. |
183
|
1
|
50
|
|
|
|
7
|
sleep 1 if $^O eq "MSWin32"; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# ->connect fails |
186
|
|
|
|
|
|
|
{ |
187
|
1
|
50
|
|
|
|
2
|
my $clientsock = IO::Socket::INET->new( |
|
1
|
|
|
|
|
8
|
|
188
|
|
|
|
|
|
|
Type => Socket::SOCK_STREAM(), |
189
|
|
|
|
|
|
|
) or die "Cannot socket() - $@"; |
190
|
1
|
|
|
|
|
194
|
$clientsock->blocking( 0 ); |
191
|
|
|
|
|
|
|
|
192
|
1
|
|
|
|
|
20
|
my $f = Future::IO->connect( $clientsock, $sockname ); |
193
|
|
|
|
|
|
|
|
194
|
1
|
|
|
|
|
88
|
ok( !eval { $f->get; 1 }, 'Future::IO->connect fails on closed server' ); |
|
1
|
|
|
|
|
4
|
|
|
0
|
|
|
|
|
0
|
|
195
|
|
|
|
|
|
|
|
196
|
1
|
|
|
|
|
349
|
is( [ $f->failure ], |
197
|
|
|
|
|
|
|
[ "connect: $errstr_ECONNREFUSED\n", connect => $clientsock, $errstr_ECONNREFUSED ], |
198
|
|
|
|
|
|
|
'Future::IO->connect failure' ); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head2 sleep |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Tests the C<< Future::IO->sleep >> method. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub run_sleep_test |
209
|
|
|
|
|
|
|
{ |
210
|
|
|
|
|
|
|
time_about sub { |
211
|
1
|
|
|
1
|
|
9
|
Future::IO->sleep( 0.2 )->get; |
212
|
1
|
|
|
1
|
0
|
8
|
}, 0.2, 'Future::IO->sleep( 0.2 ) sleeps 0.2 seconds'; |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
time_about sub { |
215
|
1
|
|
|
1
|
|
17
|
my $f1 = Future::IO->sleep( 0.1 ); |
216
|
1
|
|
|
|
|
5
|
my $f2 = Future::IO->sleep( 0.3 ); |
217
|
1
|
|
|
|
|
11
|
$f1->cancel; |
218
|
1
|
|
|
|
|
31
|
$f2->get; |
219
|
1
|
|
|
|
|
71
|
}, 0.3, 'Future::IO->sleep can be cancelled'; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
{ |
222
|
1
|
|
|
|
|
66
|
my $f1 = Future::IO->sleep( 0.1 ); |
|
1
|
|
|
|
|
9
|
|
223
|
1
|
|
|
|
|
5
|
my $f2 = Future::IO->sleep( 0.3 ); |
224
|
|
|
|
|
|
|
|
225
|
1
|
|
|
|
|
5
|
is( $f2->await, $f2, '->await returns Future' ); |
226
|
1
|
|
|
|
|
1524
|
ok( $f2->is_ready, '$f2 is ready after ->await' ); |
227
|
1
|
|
|
|
|
251
|
ok( $f1->is_ready, '$f1 is also ready after ->await' ); |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
time_about sub { |
231
|
1
|
|
|
1
|
|
8
|
Future::IO->alarm( time() + 0.2 )->get; |
232
|
1
|
|
|
|
|
254
|
}, 0.2, 'Future::IO->alarm( now + 0.2 ) sleeps 0.2 seconds'; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head2 sysread |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Tests the C<< Future::IO->sysread >> method. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub run_sysread_test |
242
|
|
|
|
|
|
|
{ |
243
|
|
|
|
|
|
|
# ->sysread yielding bytes |
244
|
|
|
|
|
|
|
{ |
245
|
1
|
50
|
|
|
|
46
|
pipe my ( $rd, $wr ) or die "Cannot pipe() - $!"; |
246
|
|
|
|
|
|
|
|
247
|
1
|
|
|
|
|
10
|
$wr->autoflush(); |
248
|
1
|
|
|
|
|
59
|
$wr->print( "BYTES" ); |
249
|
|
|
|
|
|
|
|
250
|
1
|
|
|
|
|
49
|
my $f = Future::IO->sysread( $rd, 5 ); |
251
|
|
|
|
|
|
|
|
252
|
1
|
|
|
|
|
124
|
is( scalar $f->get, "BYTES", 'Future::IO->sysread yields bytes from pipe' ); |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
# ->sysread yielding EOF |
256
|
|
|
|
|
|
|
{ |
257
|
1
|
50
|
|
1
|
0
|
3
|
pipe my ( $rd, $wr ) or die "Cannot pipe() - $!"; |
|
1
|
|
|
|
|
34
|
|
258
|
1
|
|
|
|
|
12
|
$wr->close; undef $wr; |
|
1
|
|
|
|
|
17
|
|
259
|
|
|
|
|
|
|
|
260
|
1
|
|
|
|
|
7
|
my $f = Future::IO->sysread( $rd, 1 ); |
261
|
|
|
|
|
|
|
|
262
|
1
|
|
|
|
|
89
|
is( [ $f->get ], [], 'Future::IO->sysread yields nothing on EOF' ); |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
# TODO: is there a nice portable way we can test for an IO error? |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
# ->sysread can be cancelled |
268
|
|
|
|
|
|
|
{ |
269
|
1
|
50
|
|
|
|
6200
|
pipe my ( $rd, $wr ) or die "Cannot pipe() - $!"; |
|
1
|
|
|
|
|
552
|
|
|
1
|
|
|
|
|
33
|
|
270
|
|
|
|
|
|
|
|
271
|
1
|
|
|
|
|
6
|
$wr->autoflush(); |
272
|
1
|
|
|
|
|
41
|
$wr->print( "BYTES" ); |
273
|
|
|
|
|
|
|
|
274
|
1
|
|
|
|
|
26
|
my $f1 = Future::IO->sysread( $rd, 3 ); |
275
|
1
|
|
|
|
|
86
|
my $f2 = Future::IO->sysread( $rd, 3 ); |
276
|
|
|
|
|
|
|
|
277
|
1
|
|
|
|
|
92
|
$f1->cancel; |
278
|
|
|
|
|
|
|
|
279
|
1
|
|
|
|
|
70
|
is( scalar $f2->get, "BYT", 'Future::IO->sysread can be cancelled' ); |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=head2 syswrite |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
Tests the C<< Future::IO->syswrite >> method. |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=cut |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
sub run_syswrite_test |
290
|
|
|
|
|
|
|
{ |
291
|
|
|
|
|
|
|
# ->syswrite success |
292
|
|
|
|
|
|
|
{ |
293
|
1
|
50
|
|
1
|
0
|
11
|
pipe my ( $rd, $wr ) or die "Cannot pipe() - $!"; |
|
1
|
|
|
|
|
48
|
|
294
|
|
|
|
|
|
|
|
295
|
1
|
|
|
|
|
41
|
my $f = Future::IO->syswrite( $wr, "BYTES" ); |
296
|
|
|
|
|
|
|
|
297
|
1
|
|
|
|
|
143
|
is( scalar $f->get, 5, 'Future::IO->syswrite yields written count' ); |
298
|
|
|
|
|
|
|
|
299
|
1
|
|
|
|
|
6775
|
$rd->read( my $buf, 5 ); |
300
|
1
|
|
|
|
|
36
|
is( $buf, "BYTES", 'Future::IO->syswrite wrote bytes' ); |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
# ->syswrite yielding EAGAIN |
304
|
|
|
|
|
|
|
SKIP: { |
305
|
1
|
50
|
|
|
|
7
|
$^O eq "MSWin32" and skip "MSWin32 doesn't do EAGAIN properly", 2; |
306
|
|
|
|
|
|
|
|
307
|
1
|
50
|
|
|
|
35
|
pipe my ( $rd, $wr ) or die "Cannot pipe() - $!"; |
308
|
1
|
|
|
|
|
18
|
$wr->blocking( 0 ); |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
# Attempt to fill the pipe |
311
|
1
|
|
|
|
|
20
|
$wr->syswrite( "X" x 4096 ) for 1..256; |
312
|
|
|
|
|
|
|
|
313
|
1
|
|
|
|
|
2970
|
my $f = Future::IO->syswrite( $wr, "more" ); |
314
|
|
|
|
|
|
|
|
315
|
1
|
|
|
|
|
94
|
ok( !$f->is_ready, '$f is still pending' ); |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
# Now make some space |
318
|
1
|
|
|
|
|
290
|
$rd->read( my $buf, 4096 ); |
319
|
|
|
|
|
|
|
|
320
|
1
|
|
|
|
|
37
|
is( scalar $f->get, 4, 'Future::IO->syswrite yields written count' ); |
321
|
|
|
|
|
|
|
} |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
# ->syswrite yielding EPIPE |
324
|
|
|
|
|
|
|
{ |
325
|
1
|
50
|
|
|
|
417
|
pipe my ( $rd, $wr ) or die "Cannot pipe() - $!"; |
|
1
|
|
|
|
|
36
|
|
326
|
1
|
|
|
|
|
17
|
$rd->close; undef $rd; |
|
1
|
|
|
|
|
16
|
|
327
|
|
|
|
|
|
|
|
328
|
1
|
|
|
|
|
52
|
local $SIG{PIPE} = 'IGNORE'; |
329
|
|
|
|
|
|
|
|
330
|
1
|
|
|
|
|
10
|
my $f = Future::IO->syswrite( $wr, "BYTES" ); |
331
|
|
|
|
|
|
|
|
332
|
1
|
|
|
|
|
85
|
ok( !eval { $f->get }, 'Future::IO->syswrite fails on EPIPE' ); |
|
1
|
|
|
|
|
3
|
|
333
|
|
|
|
|
|
|
|
334
|
1
|
|
|
|
|
346
|
is( [ $f->failure ], |
335
|
|
|
|
|
|
|
[ "syswrite: $errstr_EPIPE\n", syswrite => $wr, $errstr_EPIPE ], |
336
|
|
|
|
|
|
|
'Future::IO->syswrite failure for EPIPE' ); |
337
|
|
|
|
|
|
|
} |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
# ->syswrite can be cancelled |
340
|
|
|
|
|
|
|
{ |
341
|
1
|
50
|
|
|
|
451
|
pipe my ( $rd, $wr ) or die "Cannot pipe() - $!"; |
|
1
|
|
|
|
|
1292
|
|
|
1
|
|
|
|
|
46
|
|
342
|
|
|
|
|
|
|
|
343
|
1
|
|
|
|
|
8
|
my $f1 = Future::IO->syswrite( $wr, "BY" ); |
344
|
1
|
|
|
|
|
85
|
my $f2 = Future::IO->syswrite( $wr, "TES" ); |
345
|
|
|
|
|
|
|
|
346
|
1
|
|
|
|
|
88
|
$f1->cancel; |
347
|
|
|
|
|
|
|
|
348
|
1
|
|
|
|
|
81
|
is( scalar $f2->get, 3, 'Future::IO->syswrite after cancelled one still works' ); |
349
|
|
|
|
|
|
|
|
350
|
1
|
|
|
|
|
422
|
$rd->read( my $buf, 3 ); |
351
|
1
|
|
|
|
|
53
|
is( $buf, "TES", 'Cancelled Future::IO->syswrite did not write bytes' ); |
352
|
|
|
|
|
|
|
} |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
=head2 waitpid |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
Tests the C<< Future::IO->waitpid >> method. |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
=cut |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
sub run_waitpid_test |
362
|
|
|
|
|
|
|
{ |
363
|
|
|
|
|
|
|
# pre-exit |
364
|
|
|
|
|
|
|
{ |
365
|
0
|
0
|
|
|
|
|
defined( my $pid = fork() ) or die "Unable to fork() - $!"; |
366
|
0
|
0
|
|
|
|
|
if( $pid == 0 ) { |
367
|
|
|
|
|
|
|
# child |
368
|
0
|
|
|
|
|
|
exit 3; |
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
|
371
|
0
|
|
|
|
|
|
Time::HiRes::sleep 0.1; |
372
|
|
|
|
|
|
|
|
373
|
0
|
|
|
|
|
|
my $f = Future::IO->waitpid( $pid ); |
374
|
0
|
|
|
|
|
|
is( scalar $f->get, ( 3 << 8 ), 'Future::IO->waitpid yields child wait status for pre-exit' ); |
375
|
|
|
|
|
|
|
} |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
# post-exit |
378
|
|
|
|
|
|
|
{ |
379
|
0
|
0
|
|
0
|
0
|
|
defined( my $pid = fork() ) or die "Unable to fork() - $!"; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
380
|
0
|
0
|
|
|
|
|
if( $pid == 0 ) { |
381
|
|
|
|
|
|
|
# child |
382
|
0
|
|
|
|
|
|
Time::HiRes::sleep 0.1; |
383
|
0
|
|
|
|
|
|
exit 4; |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
|
386
|
0
|
|
|
|
|
|
my $f = Future::IO->waitpid( $pid ); |
387
|
0
|
|
|
|
|
|
is( scalar $f->get, ( 4 << 8 ), 'Future::IO->waitpid yields child wait status for post-exit' ); |
388
|
|
|
|
|
|
|
} |
389
|
|
|
|
|
|
|
} |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
=head1 AUTHOR |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
Paul Evans |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
=cut |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
0x55AA; |