]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40280: Disable AF_UNIX, AF_PACKET, SO_REUSE* on Emscripten (#31829)
authorChristian Heimes <christian@python.org>
Fri, 11 Mar 2022 22:25:14 +0000 (00:25 +0200)
committerGitHub <noreply@github.com>
Fri, 11 Mar 2022 22:25:14 +0000 (23:25 +0100)
Emscripten's socket emulation is limited. AF_UNIX, AF_PACKET, setsockopt(), and most SO_* constants are not supported.

Lib/socketserver.py
Modules/socketmodule.c
Modules/socketmodule.h
Tools/wasm/config.site-wasm32-emscripten

index 5e070bc3912af3ca9b53fa689d6eacd43ec50a55..30a5cfa59fe05ba55e252b9a78b710f56845d0a7 100644 (file)
@@ -465,9 +465,9 @@ class TCPServer(BaseServer):
         May be overridden.
 
         """
-        if self.allow_reuse_address:
+        if self.allow_reuse_address and hasattr(socket, "SO_REUSEADDR"):
             self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-        if self.allow_reuse_port:
+        if self.allow_reuse_port and hasattr(socket, "SO_REUSEPORT"):
             self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
         self.socket.bind(self.server_address)
         self.server_address = self.socket.getsockname()
index 3fca9f68512e808d4227263959dbccc0d0af122c..fbdd1a164db25eab492fccb5642ba47bd62f8303 100644 (file)
@@ -7933,7 +7933,7 @@ PyInit__socket(void)
 #ifdef  IPPROTO_VRRP
     PyModule_AddIntMacro(m, IPPROTO_VRRP);
 #endif
-#if defined(IPPROTO_SCTP) && !defined(__EMSCRIPTEN__)
+#ifdef  IPPROTO_SCTP
     PyModule_AddIntMacro(m, IPPROTO_SCTP);
 #endif
 #ifdef  IPPROTO_BIP
index db26c046c363795bd9037def5830fa219ec945be..1b35b11cdee6af8c94b87aa5caecf49e629ca773 100644 (file)
@@ -192,6 +192,21 @@ typedef int socklen_t;
 
 #endif /* HAVE_SOCKADDR_ALG */
 
+#ifdef __EMSCRIPTEN__
+// wasm32-emscripten sockets only support subset of IPv4 and IPv6.
+// SCTP protocol crashes runtime.
+#ifdef IPPROTO_SCTP
+#  undef IPPROTO_SCTP
+#endif
+// setsockopt() fails with ENOPROTOOPT, getsockopt only supports SO_ERROR.
+// undef SO_REUSEADDR and SO_REUSEPORT so they cannot be used.
+#ifdef SO_REUSEADDR
+#  undef SO_REUSEADDR
+#endif
+#ifdef SO_REUSEPORT
+#  undef SO_REUSEPORT
+#endif
+#endif // __EMSCRIPTEN__
 
 #ifndef Py__SOCKET_H
 #define Py__SOCKET_H
index 5eaa7933776a8d1841aee57a838958d67f1228e0..2a601987ccedf9ad5dd710ccb9fe00368a8de3cc 100644 (file)
@@ -74,8 +74,10 @@ ac_cv_func_posix_fallocate=no
 ac_cv_func_utimensat=no
 ac_cv_header_sys_ioctl_h=no
 
-# sockets are supported, but only in non-blocking mode
-# ac_cv_header_sys_socket_h=no
+# sockets are supported, but only AF_INET / AF_INET6 in non-blocking mode.
+# Disable AF_UNIX and AF_PACKET support, see socketmodule.h.
+ac_cv_header_sys_un_h=no
+ac_cv_header_netpacket_packet_h=no
 
 # aborts with bad ioctl
 ac_cv_func_openpty=no