summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md3
-rw-r--r--src/sys/socket/sockopt.rs2
-rw-r--r--test/sys/test_sockopt.rs25
3 files changed, 29 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 475386fe..5bdc4fbe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,7 +14,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
(#[1300](https://github.com/nix-rust/nix/pull/1300))
- Add support for Vsock on Android rather than just Linux.
(#[1301](https://github.com/nix-rust/nix/pull/1301))
-
+- Added `TCP_KEEPCNT` and `TCP_KEEPINTVL` TCP keepalive options.
+ (#[1283](https://github.com/nix-rust/nix/pull/1283))
### Changed
- Expose `SeekData` and `SeekHole` on all Linux targets
(#[1284](https://github.com/nix-rust/nix/pull/1284))
diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs
index cbdf6691..e41a472a 100644
--- a/src/sys/socket/sockopt.rs
+++ b/src/sys/socket/sockopt.rs
@@ -252,6 +252,8 @@ sockopt_impl!(Both, TcpKeepAlive, libc::IPPROTO_TCP, libc::TCP_KEEPALIVE, u32);
target_os = "linux",
target_os = "nacl"))]
sockopt_impl!(Both, TcpKeepIdle, libc::IPPROTO_TCP, libc::TCP_KEEPIDLE, u32);
+sockopt_impl!(Both, TcpKeepCount, libc::IPPROTO_TCP, libc::TCP_KEEPCNT, u32);
+sockopt_impl!(Both, TcpKeepInterval, libc::IPPROTO_TCP, libc::TCP_KEEPINTVL, u32);
sockopt_impl!(Both, RcvBuf, libc::SOL_SOCKET, libc::SO_RCVBUF, usize);
sockopt_impl!(Both, SndBuf, libc::SOL_SOCKET, libc::SO_SNDBUF, usize);
#[cfg(any(target_os = "android", target_os = "linux"))]
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);
+ }
+}