Skip to content

Commit 60f17d7

Browse files
committed
fixup! Added better support for unnamed unix socket addrs
Make Linux-only
1 parent fb9f0b7 commit 60f17d7

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
@@ -830,25 +830,16 @@ impl UnixAddr {
830830
}
831831

832832
/// Create a new `sockaddr_un` representing an "unnamed" unix socket address.
833+
#[cfg(any(target_os = "android", target_os = "linux"))]
834+
#[cfg_attr(docsrs, doc(cfg(all())))]
833835
pub fn new_unnamed() -> UnixAddr {
834-
#[allow(unused)]
835-
let mut ret = libc::sockaddr_un {
836+
let ret = libc::sockaddr_un {
836837
sun_family: AddressFamily::Unix as sa_family_t,
837838
.. unsafe { mem::zeroed() }
838839
};
839840

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

842-
#[cfg(any(target_os = "dragonfly",
843-
target_os = "freebsd",
844-
target_os = "ios",
845-
target_os = "macos",
846-
target_os = "netbsd",
847-
target_os = "openbsd"))]
848-
{
849-
ret.sun_len = sun_len;
850-
}
851-
852843
unsafe { UnixAddr::from_raw_parts(ret, sun_len) }
853844
}
854845

@@ -906,6 +897,8 @@ impl UnixAddr {
906897
}
907898

908899
/// Check if this address is an "unnamed" unix socket address.
900+
#[cfg(any(target_os = "android", target_os = "linux"))]
901+
#[cfg_attr(docsrs, doc(cfg(all())))]
909902
#[inline]
910903
pub fn is_unnamed(&self) -> bool {
911904
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)