Skip to content

Commit d1b7d48

Browse files
committed
Provide errno-translation wrappers around bind() and listen() on Windows.
I've seen one too many "could not bind IPv4 socket: No error" log entries from the Windows buildfarm members. Per previous discussion, this is likely caused by the fact that we're doing nothing to translate WSAGetLastError() to errno. Put in a wrapper layer to do that. If this works as expected, it should get back-patched, but let's see what happens in the buildfarm first. Discussion: <4065.1452450340@sss.pgh.pa.us>
1 parent deb71fa commit d1b7d48

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/backend/port/win32/socket.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
*/
2828
int pgwin32_noblock = 0;
2929

30+
/* Undef the macros defined in win32.h, so we can access system functions */
3031
#undef socket
32+
#undef bind
33+
#undef listen
3134
#undef accept
3235
#undef connect
3336
#undef select
@@ -261,6 +264,27 @@ pgwin32_socket(int af, int type, int protocol)
261264
return s;
262265
}
263266

267+
int
268+
pgwin32_bind(SOCKET s, struct sockaddr * addr, int *addrlen)
269+
{
270+
int res;
271+
272+
res = bind(s, addr, addrlen);
273+
if (res < 0)
274+
TranslateSocketError();
275+
return res;
276+
}
277+
278+
int
279+
pgwin32_listen(SOCKET s, int backlog)
280+
{
281+
int res;
282+
283+
res = listen(s, backlog);
284+
if (res < 0)
285+
TranslateSocketError();
286+
return res;
287+
}
264288

265289
SOCKET
266290
pgwin32_accept(SOCKET s, struct sockaddr * addr, int *addrlen)

src/include/port/win32.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,17 @@ void pg_queue_signal(int signum);
364364
/* In backend/port/win32/socket.c */
365365
#ifndef FRONTEND
366366
#define socket(af, type, protocol) pgwin32_socket(af, type, protocol)
367+
#define bind(s, addr, addrlen) pgwin32_bind(s, addr, addrlen)
368+
#define listen(s, backlog) pgwin32_listen(s, backlog)
367369
#define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen)
368370
#define connect(s, name, namelen) pgwin32_connect(s, name, namelen)
369371
#define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout)
370372
#define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags)
371373
#define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
372374

373375
SOCKET pgwin32_socket(int af, int type, int protocol);
376+
int pgwin32_bind(SOCKET s, struct sockaddr * addr, int *addrlen);
377+
int pgwin32_listen(SOCKET s, int backlog);
374378
SOCKET pgwin32_accept(SOCKET s, struct sockaddr * addr, int *addrlen);
375379
int pgwin32_connect(SOCKET s, const struct sockaddr * name, int namelen);
376380
int pgwin32_select(int nfds, fd_set *readfs, fd_set *writefds, fd_set *exceptfds, const struct timeval * timeout);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy