Skip to content

Commit

Permalink
sys::socket adding sockopt::LingerSec for Apple targets.
Browse files Browse the repository at this point in the history
```
```
  • Loading branch information
devnexen committed Dec 27, 2024
1 parent e789a7c commit 8235599
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@ sockopt_impl!(
libc::SO_LINGER,
libc::linger
);
#[cfg(apple_targets)]
sockopt_impl!(
/// `SO_LINGER_SEC` on apple targets is the genuine equivalent to
/// other platforms `SO_LINGER`. Indeed, the latter uses ticks.
LingerSec,
Both,
libc::SOL_SOCKET,
libc::SO_LINGER_SEC,
libc::linger
);
#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Expand Down
30 changes: 30 additions & 0 deletions test/sys/test_sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,36 @@ mod sockopt_impl {
assert_eq!(get_linger.l_linger, set_linger.l_linger);
}

#[cfg(apple_targets)]
sockopt_impl!(
LingerSec,
Both,
libc::SOL_SOCKET,
libc::SO_LINGER_SEC,
libc::linger
);

#[cfg(apple_targets)]
#[test]
fn test_linger_sec() {
let fd = socket(
AddressFamily::Inet,
SockType::Stream,
SockFlag::empty(),
None,
)
.unwrap();

let set_linger = libc::linger {
l_onoff: 1,
l_linger: 1,
};
setsockopt(&fd, LingerSec, &set_linger).unwrap();

let get_linger = getsockopt(&fd, Linger).unwrap();
assert_eq!(get_linger.l_linger, set_linger.l_linger * 100);
}

sockopt_impl!(KeepAlive, Both, libc::SOL_SOCKET, libc::SO_KEEPALIVE, bool);

#[test]
Expand Down

0 comments on commit 8235599

Please sign in to comment.