diff options
author | Yoav Steinberg <yoav@monfort.co.il> | 2020-08-03 10:14:19 +0300 |
---|---|---|
committer | Yoav Steinberg <yoav@monfort.co.il> | 2020-10-10 23:51:57 +0300 |
commit | fde7181f93a97595bcaf49e138933502c8027c9b (patch) | |
tree | f7c10a61d327bc60ab6581b9783a0f632bc48613 /test/sys/test_sockopt.rs | |
parent | 566e2d7dad025c9b2bef98115b584328c145675d (diff) | |
download | nix-fde7181f93a97595bcaf49e138933502c8027c9b.zip |
Add support for TCP_KEEPCNT and TCP_KEEPINTVL TCP keepalive options.
Diffstat (limited to 'test/sys/test_sockopt.rs')
-rw-r--r-- | test/sys/test_sockopt.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/sys/test_sockopt.rs b/test/sys/test_sockopt.rs index b643e420..8e2adced 100644 --- a/test/sys/test_sockopt.rs +++ b/test/sys/test_sockopt.rs @@ -67,3 +67,28 @@ fn test_bindtodevice() { val ); } + +#[test] +fn test_so_tcp_keepalive() { + let fd = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(), SockProtocol::Tcp).unwrap(); + setsockopt(fd, sockopt::KeepAlive, &true).unwrap(); + assert_eq!(getsockopt(fd, sockopt::KeepAlive).unwrap(), true); + + #[cfg(any(target_os = "android", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "linux", + target_os = "nacl"))] { + let x = getsockopt(fd, sockopt::TcpKeepIdle).unwrap(); + setsockopt(fd, sockopt::TcpKeepIdle, &(x + 1)).unwrap(); + assert_eq!(getsockopt(fd, sockopt::TcpKeepIdle).unwrap(), x + 1); + + let x = getsockopt(fd, sockopt::TcpKeepCount).unwrap(); + setsockopt(fd, sockopt::TcpKeepCount, &(x + 1)).unwrap(); + assert_eq!(getsockopt(fd, sockopt::TcpKeepCount).unwrap(), x + 1); + + let x = getsockopt(fd, sockopt::TcpKeepInterval).unwrap(); + setsockopt(fd, sockopt::TcpKeepInterval, &(x + 1)).unwrap(); + assert_eq!(getsockopt(fd, sockopt::TcpKeepInterval).unwrap(), x + 1); + } +} |