Skip to content

Commit

Permalink
Use SO_LINGER_SEC on macOS for TcpSocket::set/get_linger
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasdezeeuw committed Feb 17, 2021
1 parent b51af46 commit 175773c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ os-util = ["os-ext"]# Replaced with "os-ext" feature.
log = "0.4.8"

[target.'cfg(unix)'.dependencies]
libc = "0.2.82"
libc = "0.2.86"

[target.'cfg(windows)'.dependencies]
miow = "0.3.6"
Expand Down
6 changes: 6 additions & 0 deletions src/sys/unix/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,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,
Expand All @@ -154,6 +157,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,
Expand Down

0 comments on commit 175773c

Please sign in to comment.