From 9083f24cb303c7eba90fa4f8065c005cbf0dd9d8 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Mon, 8 Feb 2021 17:36:11 +0100 Subject: [PATCH] Use SO_LINGER_SEC on macOS for TcpSocket::set/get_linger --- Cargo.toml | 2 +- src/sys/unix/tcp.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 20f3af38..c973edcb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ net = [] log = "0.4.8" [target.'cfg(unix)'.dependencies] -libc = "0.2.82" +libc = "0.2.86" [target.'cfg(windows)'.dependencies] miow = "0.3.6" diff --git a/src/sys/unix/tcp.rs b/src/sys/unix/tcp.rs index 3378a34d..73b3b30a 100644 --- a/src/sys/unix/tcp.rs +++ b/src/sys/unix/tcp.rs @@ -136,6 +136,9 @@ pub(crate) fn set_linger(socket: TcpSocket, dur: Option) -> io::Result syscall!(setsockopt( socket, libc::SOL_SOCKET, + #[cfg(target_vendor = "apple")] + libc::SO_LINGER_SEC, + #[cfg(not(target_vendor = "apple"))] libc::SO_LINGER, &val as *const libc::linger as *const libc::c_void, size_of::() as libc::socklen_t, @@ -150,6 +153,9 @@ pub(crate) fn get_linger(socket: TcpSocket) -> io::Result> { syscall!(getsockopt( socket, libc::SOL_SOCKET, + #[cfg(target_vendor = "apple")] + libc::SO_LINGER_SEC, + #[cfg(not(target_vendor = "apple"))] libc::SO_LINGER, &mut val as *mut _ as *mut _, &mut len,