change#6328 could make close(SOCKET) return false on windows
authorGurusamy Sarathy <gsar@cpan.org>
Wed, 16 Aug 2000 23:53:42 +0000 (23:53 +0000)
committerGurusamy Sarathy <gsar@cpan.org>
Wed, 16 Aug 2000 23:53:42 +0000 (23:53 +0000)
when it shouldn't

p4raw-link: @6328 on //depot/perl: 4e94524934c1af4124b2888d9716e5304ee50ad9

p4raw-id: //depot/perl@6657

win32/win32sck.c

index f7d101b..0ce53c3 100644 (file)
@@ -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 *