Re: Fix Windows socket error checking for MinGW - Mailing list pgsql-hackers

From Noah Misch
Subject Re: Fix Windows socket error checking for MinGW
Date
Msg-id 20130817051653.GA550840@tornado.leadboat.com
Whole thread Raw
In response to Fix Windows socket error checking for MinGW  (Michael Cronenworth <mike@cchtml.com>)
Responses Re: Fix Windows socket error checking for MinGW  (Andrew Dunstan <andrew@dunslane.net>)
Re: Fix Windows socket error checking for MinGW  (Andrew Dunstan <andrew@dunslane.net>)
Re: Fix Windows socket error checking for MinGW  (Michael Cronenworth <mike@cchtml.com>)
List pgsql-hackers
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
themto the WSA constants.* Note that this will break if those constants are used for anything else* than Windows
Socketserrors.*/
 
#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

-- 
Noah Misch
EnterpriseDB                                 http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Josh Berkus
Date:
Subject: Re: [PATCH] pg_sleep(interval)
Next
From: Amit Kapila
Date:
Subject: Re: ALTER SYSTEM SET command to change postgresql.conf parameters (RE: Proposal for Allow postgresql.conf values to be changed via SQL [review])