From 3dbbc068fbb39c71f0ebf6cdc358edf2dad2b045 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Mon, 3 May 2021 10:22:14 -0500 Subject: [PATCH] Replace Socket2::r#type with manual getsockopt --- vm/src/stdlib/socket.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/vm/src/stdlib/socket.rs b/vm/src/stdlib/socket.rs index a715d2151..a93ea3868 100644 --- a/vm/src/stdlib/socket.rs +++ b/vm/src/stdlib/socket.rs @@ -142,7 +142,20 @@ impl PySocket { _ => {} } if socket_kind == -1 { - socket_kind = sock.domain().map_err(|e| e.into_pyexception(vm))?.into(); + // TODO: when socket2 cuts a new release, type will be available on all os + // socket_kind = sock.r#type().map_err(|e| e.into_pyexception(vm))?.into(); + let res = unsafe { + c::getsockopt( + sock_fileno(&sock) as _, + c::SOL_SOCKET, + c::SO_TYPE, + &mut socket_kind as *mut libc::c_int as *mut _, + &mut (std::mem::size_of::() as _), + ) + }; + if res < 0 { + return Err(super::os::errno_err(vm)); + } } cfg_if::cfg_if! { if #[cfg(any(