Re: Fix Windows socket error checking for MinGW

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: Michael Cronenworth <mike(at)cchtml(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Fix Windows socket error checking for MinGW
Date: 2013-08-18 17:02:57
Message-ID: 5210FE41.9090904@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 08/17/2013 01:16 AM, Noah Misch wrote:
> On Fri, Aug 16, 2013 at 06:56:45PM -0500, Michael Cronenworth wrote:
>> I started a thread on the general list so read that for more info.
>>
>> http://www.postgresql.org/message-id/520A6E55.40901@cchtml.com
>>
>> I'm also going to submit the patch to CommitFest.
>> +#ifndef WIN32
>> if (SOCK_ERRNO == EWOULDBLOCK)
>> +#else
>> + if (SOCK_ERRNO == WSAEWOULDBLOCK)
>> +#endif
> Thanks for looking into this. I suspect this patch is achieving the right
> runtime behavior, but some cleanup is in order. src/include/port/win32.h
> makes some effort to preempt the need for a patch like this, but the relevant
> code isn't used for MinGW:
>
> /*
> * For Microsoft Visual Studio 2010 and above we intentionally redefine
> * the regular Berkeley error constants and set them to the WSA constants.
> * Note that this will break if those constants are used for anything else
> * than Windows Sockets errors.
> */
> #if _MSC_VER >= 1600
> #pragma warning(disable:4005)
> #define EMSGSIZE WSAEMSGSIZE
> #define EAFNOSUPPORT WSAEAFNOSUPPORT
> #define EWOULDBLOCK WSAEWOULDBLOCK
> #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
> #define ECONNRESET WSAECONNRESET
> #define EINPROGRESS WSAEINPROGRESS
> #define ENOBUFS WSAENOBUFS
> #define ECONNREFUSED WSAECONNREFUSED
> #define EOPNOTSUPP WSAEOPNOTSUPP
> #pragma warning(default:4005)
> #endif
>
> I suspect we should do one of the following:
>
> 1. Redefine those constants for more (all?) compilers.
> 2. Remove that block and put #ifdef around all usage of such constants in
> frontend code, as you have done.
> 3. Remove that block and make src/backend/port/win32/socket.c frontend-usable,
> so frontend code can treat errno like backend code treats errno.
>
> What do you recommend?
>
> Thanks,
> nm
>

There is a much simpler fix, which is to do these assignments
unconditionally in src/port/win32.h. The following small change fixes
the problem for me:

diff --git a/src/include/port/win32.h b/src/include/port/win32.h
index 3a68ea4..5b93220 100644
--- a/src/include/port/win32.h
+++ b/src/include/port/win32.h
@@ -278,9 +278,8 @@ typedef int pid_t;
#ifndef EAFNOSUPPORT
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#endif
-#ifndef EWOULDBLOCK
+#undef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK
-#endif
#ifndef ECONNRESET
#define ECONNRESET WSAECONNRESET
#endif

Note that the original patch appears to be not only misguided but wrong,
in that it undid a recent important change (commit a099482c) as I read it.

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dimitri Fontaine 2013-08-18 20:20:47 Re: Feature Request on Extensions
Previous Message Stefan Kaltenbrunner 2013-08-18 16:46:30 Re: CREATE FUNCTION .. SET vs. pg_dump