Skip to content

Commit 20d4428

Browse files
committed
Provide errno-translation wrappers around bind() and listen() on Windows.
Fix Windows builds to report something useful rather than "could not bind IPv4 socket: No error" when bind() fails. Back-patch of commits d1b7d48 and 22989a8. Discussion: <4065.1452450340@sss.pgh.pa.us>
1 parent 4b52cc2 commit 20d4428

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