Skip to content

Commit 8235599

Browse files
committed
sys::socket adding sockopt::LingerSec for Apple targets.
``` ```
1 parent e789a7c commit 8235599

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/sys/socket/sockopt.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,16 @@ sockopt_impl!(
372372
libc::SO_LINGER,
373373
libc::linger
374374
);
375+
#[cfg(apple_targets)]
376+
sockopt_impl!(
377+
/// `SO_LINGER_SEC` on apple targets is the genuine equivalent to
378+
/// other platforms `SO_LINGER`. Indeed, the latter uses ticks.
379+
LingerSec,
380+
Both,
381+
libc::SOL_SOCKET,
382+
libc::SO_LINGER_SEC,
383+
libc::linger
384+
);
375385
#[cfg(feature = "net")]
376386
sockopt_impl!(
377387
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]

test/sys/test_sockopt.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,36 @@ mod sockopt_impl {
10971097
assert_eq!(get_linger.l_linger, set_linger.l_linger);
10981098
}
10991099

1100+
#[cfg(apple_targets)]
1101+
sockopt_impl!(
1102+
LingerSec,
1103+
Both,
1104+
libc::SOL_SOCKET,
1105+
libc::SO_LINGER_SEC,
1106+
libc::linger
1107+
);
1108+
1109+
#[cfg(apple_targets)]
1110+
#[test]
1111+
fn test_linger_sec() {
1112+
let fd = socket(
1113+
AddressFamily::Inet,
1114+
SockType::Stream,
1115+
SockFlag::empty(),
1116+
None,
1117+
)
1118+
.unwrap();
1119+
1120+
let set_linger = libc::linger {
1121+
l_onoff: 1,
1122+
l_linger: 1,
1123+
};
1124+
setsockopt(&fd, LingerSec, &set_linger).unwrap();
1125+
1126+
let get_linger = getsockopt(&fd, Linger).unwrap();
1127+
assert_eq!(get_linger.l_linger, set_linger.l_linger * 100);
1128+
}
1129+
11001130
sockopt_impl!(KeepAlive, Both, libc::SOL_SOCKET, libc::SO_KEEPALIVE, bool);
11011131

11021132
#[test]

0 commit comments

Comments
 (0)