Use SO_LINGER_SEC on macOS for TcpSocket::set/get_linger

This commit is contained in:
Thomas de Zeeuw
2021-02-08 17:36:11 +01:00
parent 054a80ac05
commit 9083f24cb3
2 changed files with 7 additions and 1 deletions
+1 -1
View File
@@ -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"
+6
View File
@@ -136,6 +136,9 @@ pub(crate) fn set_linger(socket: TcpSocket, dur: Option<Duration>) -> 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::<libc::linger>() as libc::socklen_t,
@@ -150,6 +153,9 @@ pub(crate) fn get_linger(socket: TcpSocket) -> io::Result<Option<Duration>> {
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,