Skip to content

Commit

Permalink
fixup! Added better support for unnamed unix socket addrs
Browse files Browse the repository at this point in the history
Make Linux-only
  • Loading branch information
stevenengler committed Nov 7, 2022
1 parent fb9f0b7 commit b1af529
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/sys/socket/addr.rs
Expand Up @@ -830,6 +830,8 @@ impl UnixAddr {
}

/// Create a new `sockaddr_un` representing an "unnamed" unix socket address.
#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn new_unnamed() -> UnixAddr {
#[allow(unused)]
let mut ret = libc::sockaddr_un {
Expand Down Expand Up @@ -906,6 +908,8 @@ impl UnixAddr {
}

/// Check if this address is an "unnamed" unix socket address.
#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all())))]
#[inline]
pub fn is_unnamed(&self) -> bool {
matches!(self.kind(), UnixAddrKind::Unnamed)
Expand Down
5 changes: 3 additions & 2 deletions test/sys/test_socket.rs
Expand Up @@ -223,7 +223,7 @@ pub fn test_addr_equality_abstract() {
}

// Test getting/setting abstract addresses (without unix socket creation)
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "android", target_os = "linux"))]
#[test]
pub fn test_abstract_uds_addr() {
let empty = String::new();
Expand All @@ -245,6 +245,7 @@ pub fn test_abstract_uds_addr() {
}

// Test getting an unnamed address (without unix socket creation)
#[cfg(any(target_os = "android", target_os = "linux"))]
#[test]
pub fn test_unnamed_uds_addr() {
use crate::nix::sys::socket::SockaddrLike;
Expand All @@ -256,7 +257,6 @@ pub fn test_unnamed_uds_addr() {
assert!(addr.path().is_none());
assert_eq!(addr.path_len(), 0);

#[cfg(target_os = "linux")]
assert!(addr.as_abstract().is_none());
}

Expand Down Expand Up @@ -1544,6 +1544,7 @@ pub fn test_named_unixdomain() {
}

// Test using unnamed unix domain addresses
#[cfg(any(target_os = "android", target_os = "linux"))]
#[test]
pub fn test_unnamed_unixdomain() {
use nix::sys::socket::{getsockname, socketpair};
Expand Down

0 comments on commit b1af529

Please sign in to comment.