[libxml2] Don't redefine socket error codes on Windows
- From: Nick Wellnhofer <nwellnhof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] Don't redefine socket error codes on Windows
- Date: Mon, 9 Oct 2017 15:08:29 +0000 (UTC)
commit 5b2324b6e007b5a03e4131877ab09f4dc8037e59
Author: Nick Wellnhofer <wellnhofer aevum de>
Date: Mon Oct 9 00:05:04 2017 +0200
Don't redefine socket error codes on Windows
Translate WSA error codes instead of blindly redefining POSIX error
codes on Windows. The redefinitions caused warnings in modern Windows
environments, but simply ifdef'ing out the redefinitions seems like
the wrong approach.
include/wsockcompat.h | 67 +++++++++++-------------------------------------
nanohttp.c | 18 +++++++++++-
2 files changed, 32 insertions(+), 53 deletions(-)
---
diff --git a/include/wsockcompat.h b/include/wsockcompat.h
index e6a1a99..cd73208 100644
--- a/include/wsockcompat.h
+++ b/include/wsockcompat.h
@@ -8,7 +8,7 @@
#ifdef _WIN32_WCE
#include <winsock.h>
#else
-#undef HAVE_ERRNO_H
+#include <errno.h>
#include <winsock2.h>
/* the following is a workaround a problem for 'inline' keyword in said
@@ -27,60 +27,25 @@
#endif
#endif
-#if defined( __MINGW32__ ) || defined( _MSC_VER )
-/* Include <errno.h> here to ensure that it doesn't get included later
- * (e.g. by iconv.h) and overwrites the definition of EWOULDBLOCK. */
-#include <errno.h>
-#undef EWOULDBLOCK
-#endif
-
#if !defined SOCKLEN_T
#define SOCKLEN_T int
#endif
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#define ESHUTDOWN WSAESHUTDOWN
-#if (!defined(_MSC_VER) || (_MSC_VER < 1600))
-#define EINPROGRESS WSAEINPROGRESS
-#define EALREADY WSAEALREADY
-#define ENOTSOCK WSAENOTSOCK
-#define EDESTADDRREQ WSAEDESTADDRREQ
-#define EMSGSIZE WSAEMSGSIZE
-#define EPROTOTYPE WSAEPROTOTYPE
-#define ENOPROTOOPT WSAENOPROTOOPT
-#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
-#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
-#define EOPNOTSUPP WSAEOPNOTSUPP
-#define EPFNOSUPPORT WSAEPFNOSUPPORT
-#define EAFNOSUPPORT WSAEAFNOSUPPORT
-#define EADDRINUSE WSAEADDRINUSE
-#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
-#define ENETDOWN WSAENETDOWN
-#define ENETUNREACH WSAENETUNREACH
-#define ENETRESET WSAENETRESET
-#define ECONNABORTED WSAECONNABORTED
-#define ECONNRESET WSAECONNRESET
-#define ENOBUFS WSAENOBUFS
-#define EISCONN WSAEISCONN
-#define ENOTCONN WSAENOTCONN
-#define ETOOMANYREFS WSAETOOMANYREFS
-#define ETIMEDOUT WSAETIMEDOUT
-#define ECONNREFUSED WSAECONNREFUSED
-#define ELOOP WSAELOOP
-#define EHOSTDOWN WSAEHOSTDOWN
-#define EHOSTUNREACH WSAEHOSTUNREACH
-#define EPROCLIM WSAEPROCLIM
-#define EUSERS WSAEUSERS
-#define EDQUOT WSAEDQUOT
-#define ESTALE WSAESTALE
-#define EREMOTE WSAEREMOTE
-/* These cause conflicts with the codes from errno.h. Since they are
- not used in the relevant code (nanoftp, nanohttp), we can leave
- them disabled.
-#define ENAMETOOLONG WSAENAMETOOLONG
-#define ENOTEMPTY WSAENOTEMPTY
-*/
-#endif /* _MSC_VER */
+#ifndef ECONNRESET
+#define ECONNRESET WSAECONNRESET
+#endif
+#ifndef EINPROGRESS
+#define EINPROGRESS WSAEINPROGRESS
+#endif
+#ifndef EINTR
+#define EINTR WSAEINTR
+#endif
+#ifndef ESHUTDOWN
+#define ESHUTDOWN WSAESHUTDOWN
+#endif
+#ifndef EWOULDBLOCK
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#endif
#endif /* __XML_WSOCKCOMPAT_H__ */
diff --git a/nanohttp.c b/nanohttp.c
index 0533102..8a2b408 100644
--- a/nanohttp.c
+++ b/nanohttp.c
@@ -182,7 +182,21 @@ xmlHTTPErrMemory(const char *extra)
*/
static int socket_errno(void) {
#ifdef _WINSOCKAPI_
- return(WSAGetLastError());
+ int err = WSAGetLastError();
+ switch(err) {
+ case WSAECONNRESET:
+ return(ECONNRESET);
+ case WSAEINPROGRESS:
+ return(EINPROGRESS);
+ case WSAEINTR:
+ return(EINTR);
+ case WSAESHUTDOWN:
+ return(ESHUTDOWN);
+ case WSAEWOULDBLOCK:
+ return(EWOULDBLOCK);
+ default:
+ return(err);
+ }
#else
return(errno);
#endif
@@ -629,7 +643,7 @@ xmlNanoHTTPRecv(xmlNanoHTTPCtxtPtr ctxt)
if ((select(ctxt->fd + 1, &rfd, NULL, NULL, &tv) < 1)
#if defined(EINTR)
- && (errno != EINTR)
+ && (socket_errno() != EINTR)
#endif
)
return (0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]