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

Inconsistency between SOCKET types makes WinSock interop with Rust's UdpSocket nontrivial #2700

Closed
recatek opened this issue Nov 13, 2023 · 4 comments
Labels
question Further information is requested

Comments

@recatek
Copy link

recatek commented Nov 13, 2023

Suggestion

This was initially brought up in #1643, but the discussion was focused primarily on HANDLE, and was closed.

Rust's built-in UdpSocket has a Windows-only as_raw_socket method that converts it into a std::os::windows::io::RawSocket, which is an alias for std::os::windows::raw::SOCKET, a u64. WinSock methods like WSAIoctl require an IntoParam<SOCKET> using windows::Win32::Networking::WinSock::SOCKET, which wraps a usize.

Since the as_raw_socket method is Windows-only to begin with, it would be nice if these two types interfaced better or had a consistent representation (perhaps ideally just using std::os::windows::raw::SOCKET).

See also rust-lang/rust#76253

@recatek recatek added the enhancement New feature or request label Nov 13, 2023
@recatek recatek changed the title Inconsistency between SOCKET types makes WinSock interop with Rust's UdpSocket nontrivial. Inconsistency between SOCKET types makes WinSock interop with Rust's UdpSocket nontrivial Nov 13, 2023
@riverar
Copy link
Collaborator

riverar commented Nov 13, 2023

Interesting. Thanks for bringing this up.

Rust has a Windows-specific socket primitive defined as such:

#[cfg(target_pointer_width = "32")]
#[doc(cfg(all()))]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type SOCKET = u32;
#[cfg(target_pointer_width = "64")]
#[doc(cfg(all()))]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type SOCKET = u64;

I'm curious how this missed becoming a usize. 🤔 Looks like the last message on rust-lang/rust#76253 was promising, maybe worth also trying to restart those std discussions?

@recatek
Copy link
Author

recatek commented Nov 13, 2023

Good point, I left a comment there pointing out the inconsistency and including the windows crate version for reference.

@ChrisDenton
Copy link
Collaborator

The standard library has strong stability guarantees (i.e. we try not to break existing code) and that issue was last active three years ago. I'm doubtful that we can change it now (but it would be good if we could).

@kennykerr kennykerr added question Further information is requested and removed enhancement New feature or request labels Nov 13, 2023
@kennykerr
Copy link
Collaborator

SOCKET is defined as UINT_PTR which is a pointer-sized unsigned integer, which is what Rust's usize is.

Closing as there's nothing for windows-rs to do here, but feel free to keep the conversation going.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants