From cb7fbcfa3af6b86b5ef80acdbf70318034e88763 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 26 Oct 2023 13:08:38 -0700 Subject: [PATCH] Adjust sockaddr lengths for illumos in more more place. Following up on #900, add illumos to the platforms that may return a Unix-domain socket address with a shorter string than the socklen value. And following up on #901, a another test for TCP_NODELAY. --- src/backend/libc/net/read_sockaddr.rs | 8 ++++---- tests/net/sockopt.rs | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/backend/libc/net/read_sockaddr.rs b/src/backend/libc/net/read_sockaddr.rs index 001424bbb..6da7a50dd 100644 --- a/src/backend/libc/net/read_sockaddr.rs +++ b/src/backend/libc/net/read_sockaddr.rs @@ -167,10 +167,10 @@ pub(crate) unsafe fn read_sockaddr( // Otherwise we expect a NUL-terminated filesystem path. // Trim off unused bytes from the end of `path_bytes`. - let path_bytes = if cfg!(target_os = "freebsd") { - // FreeBSD sometimes sets the length to longer than the - // length of the NUL-terminated string. Find the NUL and - // truncate the string accordingly. + let path_bytes = if cfg!(any(solarish, target_os = "freebsd")) { + // FreeBSD and illumos sometimes set the length to longer + // than the length of the NUL-terminated string. Find the + // NUL and truncate the string accordingly. &decode.sun_path[..decode .sun_path .iter() diff --git a/tests/net/sockopt.rs b/tests/net/sockopt.rs index d65ca591a..cd4140e84 100644 --- a/tests/net/sockopt.rs +++ b/tests/net/sockopt.rs @@ -205,12 +205,18 @@ fn test_sockopts_tcp(s: &OwnedFd) { assert!(sockopt::get_tcp_keepintvl(&s).is_ok()); } - // Set the nodelay flag; + // Set the nodelay flag. sockopt::set_tcp_nodelay(&s, true).unwrap(); // Check that the nodelay flag is set. assert!(sockopt::get_tcp_nodelay(&s).unwrap()); + // Clear the nodelay flag. + sockopt::set_tcp_nodelay(&s, false).unwrap(); + + // Check that the nodelay flag is cleared. + assert!(!sockopt::get_tcp_nodelay(&s).unwrap()); + #[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))] { // Set keepalive values: