Skip to content

Commit 6f737c9

Browse files
committed
PerlIO: don't set the error flag when reading on an EAGAIN
This allows questionable code that tries to combine select and buffered I/O to limp along. Such code is still risky due to select() checking the underlying OS handle and not the perl handle. Fixes #22883
1 parent a1af91d commit 6f737c9

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

perlio.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4466,8 +4466,7 @@ PerlIOBuf_fill(pTHX_ PerlIO *f)
44664466
if (avail <= 0) {
44674467
if (avail == 0)
44684468
PerlIOBase(f)->flags |= PERLIO_F_EOF;
4469-
else
4470-
{
4469+
else if (errno != EAGAIN) {
44714470
PerlIOBase(f)->flags |= PERLIO_F_ERROR;
44724471
PerlIO_save_errno(f);
44734472
}

t/io/perlio.t

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BEGIN {
66
skip_all_without_perlio();
77
}
88

9-
plan tests => 48;
9+
plan tests => 56;
1010

1111
use_ok('PerlIO');
1212

@@ -246,6 +246,35 @@ EOP
246246
ok !$main::PerlIO_code_injection, "Can't inject code via PerlIO->import";
247247
}
248248

249+
{
250+
use IO::Select;
251+
252+
$Config{d_pipe}
253+
or skip("No pipe", 8);
254+
255+
my ($in, $out);
256+
pipe($in, $out)
257+
or skip("Cannot pipe: $!", 8);
258+
259+
$in->blocking(0)
260+
or skip_all("Cannot make pipe non-blocking");
261+
262+
my $line = <$in>;
263+
is($line, undef, "error reading (readline)");
264+
ok(!$in->error, "but did not set error flag (readline)");
265+
{
266+
local $::TODO = "read() uses the error flag to detect errors";
267+
is(read($in, my $buf, 10), undef, "error reading (read)");
268+
}
269+
ok(!$in->error, "but did not set error flag (read)");
270+
close $out;
271+
$line = <$in>;
272+
is($line, undef, "nothing to read, but eof");
273+
ok(!$in->error, "still did not set error flag");
274+
ok($in->eof, "did set eof");
275+
ok(close($in), "close success");
276+
}
277+
249278
END {
250279
unlink_all $txt;
251280
unlink_all $bin;

0 commit comments

Comments
 (0)