From f5458e3a4f5fed75a7fe0b26182af4c52e76a186 Mon Sep 17 00:00:00 2001 From: Stephen Oberholtzer Date: Tue, 16 Aug 2011 09:35:54 -0400 Subject: [PATCH] Fix setting sockets nonblocking in Win32 --- dist/IO/IO.xs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/dist/IO/IO.xs b/dist/IO/IO.xs index e8e9e55..dfbe3bd 100644 --- a/dist/IO/IO.xs +++ b/dist/IO/IO.xs @@ -122,8 +122,20 @@ io_blocking(pTHX_ InputStream f, int block) return RETVAL; #else # ifdef WIN32 - char flags = (char)block; - return ioctl(PerlIO_fileno(f), FIONBIO, &flags); + if (block >= 0) { + unsigned long flags = !block; + /* ioctl claims to take char* but really needs a u_long sized buffer */ + const int ret = ioctl(PerlIO_fileno(f), FIONBIO, (char*)&flags); + if (ret != 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 + * to tell that the ioctl succeeded. + */ + return flags; + } + /* TODO: Perhaps set $! to ENOTSUP? */ + return -1; # else return -1; # endif -- 2.7.4