Skip to content

Commit 16051ea

Browse files
Added test for keepalive sockopts.
1 parent 767a8c5 commit 16051ea

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/sys/test_sockopt.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,22 @@ fn test_bindtodevice() {
6767
val
6868
);
6969
}
70+
71+
#[test]
72+
fn test_so_tcp_keepalive() {
73+
let fd = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(), SockProtocol::Tcp).unwrap();
74+
setsockopt(fd, sockopt::KeepAlive, &true).unwrap();
75+
assert_eq!(getsockopt(fd, sockopt::KeepAlive).unwrap(), true);
76+
77+
let x = getsockopt(fd, sockopt::TcpKeepIdle).unwrap();
78+
setsockopt(fd, sockopt::TcpKeepIdle, &(x+1)).unwrap();
79+
assert_eq!(getsockopt(fd, sockopt::TcpKeepIdle).unwrap(), x+1);
80+
81+
let x = getsockopt(fd, sockopt::TcpKeepCount).unwrap();
82+
setsockopt(fd, sockopt::TcpKeepCount, &(x+1)).unwrap();
83+
assert_eq!(getsockopt(fd, sockopt::TcpKeepCount).unwrap(), x+1);
84+
85+
let x = getsockopt(fd, sockopt::TcpKeepInterval).unwrap();
86+
setsockopt(fd, sockopt::TcpKeepInterval, &(x+1)).unwrap();
87+
assert_eq!(getsockopt(fd, sockopt::TcpKeepInterval).unwrap(), x+1);
88+
}

0 commit comments

Comments
 (0)