diff --git a/dist/IO/IO.xs b/dist/IO/IO.xs index e5baaad10527..2822b370f2eb 100644 --- a/dist/IO/IO.xs +++ b/dist/IO/IO.xs @@ -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; @@ -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; @@ -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 diff --git a/dist/IO/t/io_xs.t b/dist/IO/t/io_xs.t index c9b8836b32e9..75d418b368e4 100644 --- a/dist/IO/t/io_xs.t +++ b/dist/IO/t/io_xs.t @@ -11,7 +11,7 @@ BEGIN { } } -use Test::More tests => 11; +use Test::More tests => 13; use IO::File; use IO::Seekable; @@ -60,7 +60,6 @@ SKIP: or diag "sync(): ", $!; } - SKIP: { # gh 6799 # @@ -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"); +}