Re: Why doesn't src/backend/port/win32/socket.c implement bind()? - Mailing list pgsql-hackers

From Magnus Hagander
Subject Re: Why doesn't src/backend/port/win32/socket.c implement bind()?
Date
Msg-id CABUevExPNDmQWT9H2GSs72G5itjx0ow7e_A8Djg38o2oNH-zvw@mail.gmail.com
Whole thread Raw
In response to Re: Why doesn't src/backend/port/win32/socket.c implement bind()?  (Amit Kapila <amit.kapila16@gmail.com>)
Responses Re: Why doesn't src/backend/port/win32/socket.c implement bind()?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers


On Mon, Jan 11, 2016 at 6:19 AM, Amit Kapila <amit.kapila16@gmail.com> wrote:
On Sun, Jan 10, 2016 at 11:55 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Some of the Windows buildfarm members occasionally fail like this:
>
> LOG:  could not bind IPv4 socket: No error
> HINT:  Is another postmaster already running on port 64470? If not, wait a few seconds and retry.
> WARNING:  could not create listen socket for "127.0.0.1"
> FATAL:  could not create any TCP/IP sockets
>
> (bowerbird, in particular, has a few recent examples)
>
> I think the reason why we're getting "No error" instead of a useful
> strerror report is that socket.c doesn't provide an implementation
> of bind() that includes TranslateSocketError().
>

listen also doesn't have such an implementation and probably few others.

The reason they don't is that when this compatibility layer was written, it was to support the signal emulation. So the calls that were put in there were the ones that we need(ed) to be able to interrupt with a signal. As both bind() and listen() are not blocking commands (at least not normally), there is no need to interrupt them, and thus there is no function in socket.c for them.

I don't think anybody at the time was even considering the error handling. Only insofar as handling the calls that were very clearly not the same as the Unix variants. listen/bind were just missed.

 
>  Why is that?
>

Not sure, but I could see that bind and listen doesn't have the equivalent
Win sock API (checked in winsock2.h) and while googling on same,
I found that there are reasons [1] why Win Sockets doesn't have the
equivalent of some of the socket API's.

I think here we should add a win32 wrapper over bind and listen
API's which ensures TranslateSocketError() should be called for
error cases.
 

Yeah, that seems like a good idea.


--

pgsql-hackers by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: No Issue Tracker - Say it Ain't So!
Next
From: Tomas Vondra
Date:
Subject: Re: PATCH: add pg_current_xlog_flush_location function