Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,19 @@ def testWindowsSpecificConstants(self):
socket.IPPROTO_L2TP
socket.IPPROTO_SCTP

@unittest.skipIf(support.is_wasi, "WASI is missing these methods")
def test_socket_methods(self):
# socket methods that depend on a configure HAVE_ check. They should
# be present on all platforms except WASI.
names = [
"_accept", "bind", "connect", "connect_ex", "getpeername",
"getsockname", "listen", "recvfrom", "recvfrom_into", "sendto",
"setsockopt", "shutdown"
]
for name in names:
if not hasattr(socket.socket, name):
self.fail(f"socket method {name} is missing")

@unittest.skipUnless(sys.platform == 'darwin', 'macOS specific test')
@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'IPv6 required for this test')
def test3542SocketOptions(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Python now skips missing :mod:`socket` functions and methods on WASI. WASI can only create sockets from existing fd / accept and has no netdb.
2 changes: 2 additions & 0 deletions Modules/addrinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ struct sockaddr_storage {
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ENABLE_IPV6
extern void freehostent(struct hostent *);
#endif
#ifdef __cplusplus
}
#endif
5 changes: 5 additions & 0 deletions Modules/getaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
# define FAITH
#endif

#ifdef HAVE_NETDB_H
#define HAVE_GETADDRINFO 1

#define SUCCESS 0
#define GAI_ANY 0
#define YES 1
Expand Down Expand Up @@ -636,3 +639,5 @@ get_addr(hostname, af, res, pai, port0)
*res = NULL;
return error;
}

#endif // HAVE_NETDB_H
4 changes: 4 additions & 0 deletions Modules/getnameinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
#include "addrinfo.h"
#endif

#ifdef HAVE_NETDB_H
#define HAVE_GETNAMEINFO 1

#define SUCCESS 0
#define YES 1
#define NO 0
Expand Down Expand Up @@ -211,3 +214,4 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
}
return SUCCESS;
}
#endif // HAVE_NETDB_H
Loading