From: Gurusamy Sarathy Date: Wed, 16 Aug 2000 23:53:42 +0000 (+0000) Subject: change#6328 could make close(SOCKET) return false on windows X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d3d49e297818ad29e57e852d02bbe2b2bab8a74c;p=p5sagit%2Fp5-mst-13.2.git change#6328 could make close(SOCKET) return false on windows when it shouldn't p4raw-link: @6328 on //depot/perl: 4e94524934c1af4124b2888d9716e5304ee50ad9 p4raw-id: //depot/perl@6657 --- diff --git a/win32/win32sck.c b/win32/win32sck.c index f7d101b..0ce53c3 100644 --- a/win32/win32sck.c +++ b/win32/win32sck.c @@ -426,15 +426,24 @@ my_fclose (FILE *pf) if (!wsock_started) /* No WinSock? */ return(fclose(pf)); /* Then not a socket. */ osf = TO_SOCKET(fileno(pf));/* Get it now before it's gone! */ - if (osf != -1 - && closesocket(osf) == SOCKET_ERROR - && WSAGetLastError() != WSAENOTSOCK) - { - (void)fclose(pf); - return EOF; + if (osf != -1) { + int err; + win32_fflush(pf); + err = closesocket(osf); + if (err == 0) { + (void)fclose(pf); /* handle already closed, ignore error */ + return 0; + } + else if (err == SOCKET_ERROR) { + err = WSAGetLastError(); + if (err != WSAENOTSOCK) { + (void)fclose(pf); + errno = err; + return EOF; + } + } } - else - return fclose(pf); + return fclose(pf); } struct hostent *