Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-40280: Disable AF_UNIX, AF_PACKET, SO_REUSE* on Emscripten #31829

Merged
merged 1 commit into from
Mar 11, 2022
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
bpo-40280: Disable AF_UNIX, AF_PACKET, SO_REUSE* on Emscripten
Emscripten's socket emulation is limited. AF_UNIX, AF_PACKET,
setsockopt(), and most SO_* constants are not supported.
  • Loading branch information
tiran committed Mar 11, 2022
commit bc817034f95e6f94b34a2013afdbbc7b87ac1971
4 changes: 2 additions & 2 deletions Lib/socketserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,9 @@ def server_bind(self):
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()
Expand Down
2 changes: 1 addition & 1 deletion Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions Modules/socketmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions Tools/wasm/config.site-wasm32-emscripten
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down