From 05f1386fca08d441d32fe46d23a45249be40a2d1 Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" <69878+youknowone@users.noreply.github.com> Date: Wed, 23 Sep 2026 18:28:08 +0900 Subject: [PATCH] host_env: publish remaining Windows socket constants (#8792) * host_env: publish remaining Windows socket constants Windows SOMAXCONN follows winsock2.h (0x7fffffff), not the Winsock 1.1 value windows-sys still exports. The socket module takes the signed INADDR group constants and the other Winsock names host_env already defines. Assisted-by: Grok * test_socket: expect Bluetooth constants to pass on Windows The Windows names this test reads are published now, so the blanket expectedFailure is an unexpected success there. Other platforms still miss BTPROTO_HCI and the rest of the non-Windows set. Assisted-by: Grok --- Lib/test/test_socket.py | 4 +++- crates/host_env/src/socket.rs | 10 +++++++--- crates/stdlib/src/socket.rs | 31 ++++++++++++++++++------------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index b59709680..615cc1c65 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -2698,7 +2698,9 @@ class BasicVSOCKTest(unittest.TestCase): 'Bluetooth sockets required for this test.') class BasicBluetoothTest(unittest.TestCase): - @unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module 'socket' has no attribute 'BTPROTO_RFCOMM' + # Windows publishes the names below. Other platforms still miss + # BTPROTO_HCI and the rest of the non-Windows set. + @(unittest.expectedFailure if sys.platform != "win32" else (lambda func: func)) def testBluetoothConstants(self): socket.BDADDR_ANY socket.BDADDR_LOCAL diff --git a/crates/host_env/src/socket.rs b/crates/host_env/src/socket.rs index cb4bc9706..c70f4a160 100644 --- a/crates/host_env/src/socket.rs +++ b/crates/host_env/src/socket.rs @@ -1164,9 +1164,9 @@ pub use windows_sys::Win32::Networking::WinSock::{ SO_DONTROUTE, SO_ERROR, SO_KEEPALIVE, SO_LINGER, SO_OOBINLINE, SO_RCVBUF, SO_RCVTIMEO, SO_REUSEADDR, SO_SNDBUF, SO_SNDTIMEO, SO_TYPE, SO_USELOOPBACK, SOCK_DGRAM, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_STREAM, SOCKET_ERROR, SOCKET_ERROR as SOCKET_ERROR_CODE, SOL_IP, - SOL_SOCKET, SOMAXCONN, TCP_MAXSEG, TCP_NODELAY, WSAEBADF, WSAECONNABORTED, WSAECONNRESET, - WSAEINTR, WSAENOTSOCK, WSAEWOULDBLOCK, getprotobyname, getservbyname, getservbyport, - getsockopt, setsockopt, + SOL_SOCKET, TCP_MAXSEG, TCP_NODELAY, WSAEBADF, WSAECONNABORTED, WSAECONNRESET, WSAEINTR, + WSAENOTSOCK, WSAEWOULDBLOCK, getprotobyname, getservbyname, getservbyport, getsockopt, + setsockopt, }; #[cfg(windows)] @@ -1204,6 +1204,10 @@ pub const AI_NUMERICHOST: i32 = windows_sys::Win32::Networking::WinSock::AI_NUME #[cfg(windows)] pub const FROM_PROTOCOL_INFO_VALUE: i32 = FROM_PROTOCOL_INFO; +/// `winsock2.h` `SOMAXCONN`. windows-sys still exports the Winsock 1.1 value 5. +#[cfg(windows)] +pub const SOMAXCONN: i32 = 0x7fff_ffff; + /// Signed C-long readings of option words, plus names the Winsock headers /// do not define that the module still carries. #[cfg(windows)] diff --git a/crates/stdlib/src/socket.rs b/crates/stdlib/src/socket.rs index 3d6229b45..4749be889 100644 --- a/crates/stdlib/src/socket.rs +++ b/crates/stdlib/src/socket.rs @@ -225,15 +225,7 @@ mod _socket { #[cfg(windows)] #[pyattr] - const INADDR_UNSPEC_GROUP: u32 = 0xe0000000; - - #[cfg(windows)] - #[pyattr] - const INADDR_ALLHOSTS_GROUP: u32 = 0xe0000001; - - #[cfg(windows)] - #[pyattr] - const INADDR_MAX_LOCAL_GROUP: u32 = 0xe00000ff; + use host_socket::{INADDR_ALLHOSTS_GROUP, INADDR_MAX_LOCAL_GROUP, INADDR_UNSPEC_GROUP}; #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] #[pyattr] @@ -665,12 +657,25 @@ mod _socket { #[cfg(windows)] #[pyattr] use host_socket::{ - AF_BLUETOOTH, AF_HYPERV, AF_IRDA, AF_SNA, BTHPROTO_RFCOMM, HV_PROTOCOL_RAW, - HVSOCKET_ADDRESS_FLAG_PASSTHRU, HVSOCKET_CONNECT_TIMEOUT, HVSOCKET_CONNECT_TIMEOUT_MAX, - HVSOCKET_CONNECTED_SUSPEND, IPPROTO_CBT, IPPROTO_ICLFXBM, IPPROTO_IGP, IPPROTO_L2TP, - IPPROTO_PGM, IPPROTO_RDP, IPPROTO_SCTP, IPPROTO_ST, SIO_TCP_SET_ACK_FREQUENCY, + AF_BLUETOOTH, AF_HYPERV, AF_IRDA, AF_SNA, BTHPROTO_RFCOMM, + BTHPROTO_RFCOMM as BTPROTO_RFCOMM, HV_PROTOCOL_RAW, HVSOCKET_ADDRESS_FLAG_PASSTHRU, + HVSOCKET_CONNECT_TIMEOUT, HVSOCKET_CONNECT_TIMEOUT_MAX, HVSOCKET_CONNECTED_SUSPEND, + IP_ADD_SOURCE_MEMBERSHIP, IP_BLOCK_SOURCE, IP_DROP_SOURCE_MEMBERSHIP, IP_PKTINFO, + IP_RECVERR, IP_RECVTOS, IP_RECVTTL, IP_UNBLOCK_SOURCE, IPPROTO_CBT, IPPROTO_ICLFXBM, + IPPROTO_IGP, IPPROTO_L2TP, IPPROTO_PGM, IPPROTO_RDP, IPPROTO_SCTP, IPPROTO_ST, + IPV6_RECVERR, MSG_ERRQUEUE, RCVALL_MAX, SIO_TCP_SET_ACK_FREQUENCY, SO_ACCEPTCONN, + SO_BTH_ENCRYPT, SO_BTH_MTU, SO_BTH_MTU_MAX, SO_BTH_MTU_MIN, SO_DEBUG, SO_DONTROUTE, + SO_ORIGINAL_DST, SO_RCVLOWAT, SO_RCVTIMEO, SO_SNDLOWAT, SO_SNDTIMEO, SOL_RFCOMM, + TCP_FASTOPEN, TCP_KEEPCNT, TCP_KEEPIDLE, TCP_KEEPINTVL, }; + #[cfg(windows)] + #[pyattr] + const BDADDR_ANY: &str = host_socket::BDADDR_ANY; + #[cfg(windows)] + #[pyattr] + const BDADDR_LOCAL: &str = host_socket::BDADDR_LOCAL; + #[cfg(windows)] #[pyattr] const HV_GUID_ZERO: &str = host_socket::HV_GUID_ZERO;