Skip to content

Commit

Permalink
use the supplied handle in IO::Handle::blocking() on Win32
Browse files Browse the repository at this point in the history
The refactor in 375ed12 meant that fd was initialized to -1,
rather than PerlIO_fileno(f) on Win32.

fixes #17455
  • Loading branch information
tonycoz committed Oct 25, 2023
1 parent f8f432a commit 66975c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
9 changes: 4 additions & 5 deletions dist/IO/IO.xs
Expand Up @@ -72,8 +72,6 @@ static int
io_blocking(pTHX_ InputStream f, int block)
{
int fd = -1;
#if defined(HAS_FCNTL)
int RETVAL;
if (!f) {
errno = EBADF;
return -1;
Expand All @@ -83,7 +81,8 @@ io_blocking(pTHX_ InputStream f, int block)
errno = EBADF;
return -1;
}
RETVAL = fcntl(fd, F_GETFL, 0);
#if defined(HAS_FCNTL)
int RETVAL = fcntl(fd, F_GETFL, 0);
if (RETVAL >= 0) {
int mode = RETVAL;
int newmode = mode;
Expand Down Expand Up @@ -129,8 +128,8 @@ io_blocking(pTHX_ InputStream f, int block)
if (block >= 0) {
unsigned long flags = !block;
/* ioctl claims to take char* but really needs a u_long sized buffer */
const int ret = ioctl(fd, FIONBIO, (char*)&flags);
if (ret != 0)

if (ioctl(fd, FIONBIO, (char*)&flags) != 0)
return -1;
/* Win32 has no way to get the current blocking status of a socket.
* However, we don't want to just return undef, because there's no way
Expand Down
22 changes: 20 additions & 2 deletions dist/IO/t/io_xs.t
Expand Up @@ -11,7 +11,7 @@ BEGIN {
}
}

use Test::More tests => 11;
use Test::More tests => 13;
use IO::File;
use IO::Seekable;

Expand Down Expand Up @@ -60,7 +60,6 @@ SKIP:
or diag "sync(): ", $!;
}


SKIP: {
# gh 6799
#
Expand All @@ -86,3 +85,22 @@ SKIP: {
ok(!$fh->error, "no spurious error reported by error()");
close $fh;
}

SKIP:
{
# gh #17455
# the IO::Handle::blocking() implementation on Win32 was always using
# a fd of -1.
# A typical caller would be creating the socket using IO::Socket
# which blesses the result into that class and that provides its own
# blocking implementation and doesn't have this problem.
#
# The issue here was Win32 specific, but nothing else appears to test
# this implementation.
use Socket;
ok(socket(my $sock, PF_INET, SOCK_STREAM, getprotobyname('tcp')),
"create a socket to make non-blocking")
or skip "couldn't create the socket: $!", 1;
ok(defined IO::Handle::blocking($sock, 0),
"successfully make socket non-blocking");
}

0 comments on commit 66975c2

Please sign in to comment.