@@ -67,3 +67,28 @@ fn test_bindtodevice() {
67
67
val
68
68
) ;
69
69
}
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
+ #[ cfg( any( target_os = "android" ,
78
+ target_os = "dragonfly" ,
79
+ target_os = "freebsd" ,
80
+ target_os = "linux" ,
81
+ target_os = "nacl" ) ) ] {
82
+ let x = getsockopt ( fd, sockopt:: TcpKeepIdle ) . unwrap ( ) ;
83
+ setsockopt ( fd, sockopt:: TcpKeepIdle , & ( x + 1 ) ) . unwrap ( ) ;
84
+ assert_eq ! ( getsockopt( fd, sockopt:: TcpKeepIdle ) . unwrap( ) , x + 1 ) ;
85
+
86
+ let x = getsockopt ( fd, sockopt:: TcpKeepCount ) . unwrap ( ) ;
87
+ setsockopt ( fd, sockopt:: TcpKeepCount , & ( x + 1 ) ) . unwrap ( ) ;
88
+ assert_eq ! ( getsockopt( fd, sockopt:: TcpKeepCount ) . unwrap( ) , x + 1 ) ;
89
+
90
+ let x = getsockopt ( fd, sockopt:: TcpKeepInterval ) . unwrap ( ) ;
91
+ setsockopt ( fd, sockopt:: TcpKeepInterval , & ( x + 1 ) ) . unwrap ( ) ;
92
+ assert_eq ! ( getsockopt( fd, sockopt:: TcpKeepInterval ) . unwrap( ) , x + 1 ) ;
93
+ }
94
+ }
0 commit comments