Skip to content

Commit 49bab98

Browse files
committed
fixup! Added better support for unnamed unix socket addrs
Make Linux-only
1 parent 8884ea3 commit 49bab98

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

src/sys/socket/addr.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -886,25 +886,16 @@ impl UnixAddr {
886886
}
887887

888888
/// Create a new `sockaddr_un` representing an "unnamed" unix socket address.
889+
#[cfg(any(target_os = "android", target_os = "linux"))]
890+
#[cfg_attr(docsrs, doc(cfg(all())))]
889891
pub fn new_unnamed() -> UnixAddr {
890-
#[allow(unused)]
891-
let mut ret = libc::sockaddr_un {
892+
let ret = libc::sockaddr_un {
892893
sun_family: AddressFamily::Unix as sa_family_t,
893894
.. unsafe { mem::zeroed() }
894895
};
895896

896897
let sun_len: u8 = offset_of!(libc::sockaddr_un, sun_path).try_into().unwrap();
897898

898-
#[cfg(any(target_os = "dragonfly",
899-
target_os = "freebsd",
900-
target_os = "ios",
901-
target_os = "macos",
902-
target_os = "netbsd",
903-
target_os = "openbsd"))]
904-
{
905-
ret.sun_len = sun_len;
906-
}
907-
908899
unsafe { UnixAddr::from_raw_parts(ret, sun_len) }
909900
}
910901

@@ -965,6 +956,8 @@ impl UnixAddr {
965956
}
966957

967958
/// Check if this address is an "unnamed" unix socket address.
959+
#[cfg(any(target_os = "android", target_os = "linux"))]
960+
#[cfg_attr(docsrs, doc(cfg(all())))]
968961
#[inline]
969962
pub fn is_unnamed(&self) -> bool {
970963
matches!(self.kind(), UnixAddrKind::Unnamed)

test/sys/test_socket.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ pub fn test_addr_equality_abstract() {
223223
}
224224

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

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

259-
#[cfg(target_os = "linux")]
260260
assert!(addr.as_abstract().is_none());
261261
}
262262

@@ -1544,6 +1544,7 @@ pub fn test_named_unixdomain() {
15441544
}
15451545

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

0 commit comments

Comments
 (0)