closesocket in MinGW

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
kosh
Posts: 72
Joined: Sun Sep 13, 2009 5:38 am
Location: Japan
Contact:

closesocket in MinGW

Post by kosh »

Hi.

This patch is resolve problems which fail to close the file descriptor.

Code: Select all

diff --git a/nl-sock.c b/nl-sock.c
index 00efa7b..9acdaa7 100644
--- a/nl-sock.c
+++ b/nl-sock.c
@@ -1485,7 +1485,12 @@ handle = open(logFile, O_RDWR | O_APPEND | O_BINARY | O_CREAT,
 if(write(handle, text, strlen(text)) < 0) return;
 if(newLine) 
     if(write(handle, &LINE_FEED, LINE_FEED_LEN) < 0) return;
+
+#ifdef WINDOWS
+_close(handle);
+#else
 close(handle);
+#endif
 }
 
 
diff --git a/nl-web.c b/nl-web.c
index 518fca0..99b516a 100644
--- a/nl-web.c
+++ b/nl-web.c
@@ -1183,7 +1183,11 @@ switch(type)
             }
 
         transferred = readPayLoad(size, buff, outFile, request);
+#ifdef WINDOWS
+        _close(outFile);
+#else
         close(outFile);
+#endif
 
         if(transferred != -1)
             {
Or, define 'closesocket' function for closing the only socket descriptor.
In this case, patch will become a little bigger: http://pastebin.com/gAYUsp1Y

Code: Select all

 #ifdef WINDOWS
-#define close(s) closesocket(s)
 #else
 #include <sys/socket.h>
 #define SOCKET_ERROR -1
 #define INVALID_SOCKET -1
+#define closesocket(s) close(s)
 #endif

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: closesocket in MinGW

Post by Lutz »


Locked