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

Replace Unix SocketAddr with std version #1749

Merged
merged 9 commits into from
Jun 9, 2024
Merged

Replace Unix SocketAddr with std version #1749

merged 9 commits into from
Jun 9, 2024

Conversation

Thomasdezeeuw
Copy link
Collaborator

@Thomasdezeeuw Thomasdezeeuw commented Dec 24, 2023

Replaces mio::net::SocketAddr with std::os::unix::net::SocketAddr.

With this change the path based API to create the sockets ({UnixDatagram,UnixListener}::bind and UnixStream::connect) will no longer work with abstract namespaces. For that the _addr variant must be used and the address created by using SocketAddr::from_abstract_name (part of the std::os::linux::net::SocketAddrExt trait).

Adds UnixDatagram::bind_addr to match UnixStream::connect_addr and UnixListener::bind_addr.

Expands the unix_listener_abstract_namespace test to actually create a listener and use it.

Closes #1527

src/sys/unix/uds/mod.rs Outdated Show resolved Hide resolved
src/sys/unix/uds/mod.rs Outdated Show resolved Hide resolved
Comment on lines 46 to 47
#[cfg(target_os = "linux")]
None => match address.as_abstract_name() {
Some(name) => {
offset += 1;
name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that technically this change does not mean that the MSRV cannot be lower than 1.70.0. You can use a build script to detect the rustc version and only include this branch if the rustc is at least 1.70.0. This works because the user cannot construct a SocketAddr with an abstract name on older rustc.

We used this technique in Tokio to support the IO safety traits before our MSRV supported them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's increasing the MSRV, that was the goal for Mio v1.

I'm not going to mess around with a build script. I've seen it in the log and libc crates as well as a few others and it's always been a pain to maintain them. Mio v1 is simply going to have a higher MSRV.

src/sys/unix/uds/mod.rs Outdated Show resolved Hide resolved
src/sys/unix/uds/mod.rs Outdated Show resolved Hide resolved
Replaces mio::net::SocketAddr with std::os::unix::net::SocketAddr.

With this change the path based API to create the sockets
({UnixDatagram,UnixListener}::bind and UnixStream::connect) will no
longer work with abstract namespaces. For that the _addr variant must be
used and the address created by using SocketAddr::from_abstract_name
(part of the std::os::linux::net::SocketAddrExt trait).

Adds UnixDatagram::bind_addr to match UnixStream::connect_addr and
UnixListener::bind_addr.

Expands the unix_listener_abstract_namespace test to actually create a
listener and use it.

Closes #1527
It seems to return a length of 16 and an all zero address for unnamed
Unix addresses.
mem::zeroed has been undeprecrated.
@Thomasdezeeuw
Copy link
Collaborator Author

Rebased this and address all feedback from @Darksonn (only took me six months 😅)

Matching what we do in the unix_addr function.
Should have expected that Darwin copied it from FreeBSD, but oh well.
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change the path based API to create the sockets ({UnixDatagram,UnixListener}::bind and UnixStream::connect) will no longer work with abstract namespaces. For that the _addr variant must be used and the address created by using SocketAddr::from_abstract_name (part of the std::os::linux::net::SocketAddrExt trait).

Please make sure to mention this in your v1.0.0 changelog under the list of breaking changes.

@Thomasdezeeuw
Copy link
Collaborator Author

Please make sure to mention this in your v1.0.0 changelog under the list of breaking changes.

👍 the changelog will be fun to make for this release 😉

@Thomasdezeeuw Thomasdezeeuw merged commit 9f1e9ff into master Jun 9, 2024
31 checks passed
@Thomasdezeeuw Thomasdezeeuw deleted the thomas/1527 branch June 9, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use std::os::unix::net::SocketAddr instead of mio::net::SocketAddr
2 participants