closesocket in MinGW

Started by kosh, August 28, 2013, 11:42:14 PM

Previous topic - Next topic

kosh

Hi.



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


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">//http://pastebin.com/gAYUsp1Y


#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

#1
Thank you very much!



changes here: http://www.newlisp.org/downloads/development/inprogress/">http://www.newlisp.org/downloads/develo ... nprogress/">http://www.newlisp.org/downloads/development/inprogress/