@@ -1063,13 +1063,49 @@ fn test_ipv6_recv_traffic_class_opts() {
1063
1063
) ;
1064
1064
}
1065
1065
1066
+ #[ cfg( apple_targets) ]
1067
+ #[ test]
1068
+ fn test_linger_sec ( ) {
1069
+ let fd = socket (
1070
+ AddressFamily :: Inet ,
1071
+ SockType :: Stream ,
1072
+ SockFlag :: empty ( ) ,
1073
+ None ,
1074
+ )
1075
+ . unwrap ( ) ;
1076
+
1077
+ let set_linger = libc:: linger {
1078
+ l_onoff : 1 ,
1079
+ l_linger : 1 ,
1080
+ } ;
1081
+ setsockopt ( & fd, sockopt:: LingerSec , & set_linger) . unwrap ( ) ;
1082
+
1083
+ let get_linger = getsockopt ( & fd, sockopt:: Linger ) . unwrap ( ) ;
1084
+ assert_eq ! ( get_linger. l_linger, set_linger. l_linger * 100 ) ;
1085
+ }
1086
+
1066
1087
/// Users should be able to define their own sockopts.
1067
1088
mod sockopt_impl {
1068
1089
use nix:: sys:: socket:: {
1069
1090
getsockopt, setsockopt, socket, AddressFamily , SockFlag , SockProtocol ,
1070
1091
SockType ,
1071
1092
} ;
1072
1093
1094
+ sockopt_impl ! ( KeepAlive , Both , libc:: SOL_SOCKET , libc:: SO_KEEPALIVE , bool ) ;
1095
+
1096
+ #[ test]
1097
+ fn test_so_tcp_keepalive ( ) {
1098
+ let fd = socket (
1099
+ AddressFamily :: Inet ,
1100
+ SockType :: Stream ,
1101
+ SockFlag :: empty ( ) ,
1102
+ SockProtocol :: Tcp ,
1103
+ )
1104
+ . unwrap ( ) ;
1105
+ setsockopt ( & fd, KeepAlive , & true ) . unwrap ( ) ;
1106
+ assert ! ( getsockopt( & fd, KeepAlive ) . unwrap( ) ) ;
1107
+ }
1108
+
1073
1109
sockopt_impl ! (
1074
1110
Linger ,
1075
1111
Both ,
@@ -1096,19 +1132,4 @@ mod sockopt_impl {
1096
1132
let get_linger = getsockopt ( & fd, Linger ) . unwrap ( ) ;
1097
1133
assert_eq ! ( get_linger. l_linger, set_linger. l_linger) ;
1098
1134
}
1099
-
1100
- sockopt_impl ! ( KeepAlive , Both , libc:: SOL_SOCKET , libc:: SO_KEEPALIVE , bool ) ;
1101
-
1102
- #[ test]
1103
- fn test_so_tcp_keepalive ( ) {
1104
- let fd = socket (
1105
- AddressFamily :: Inet ,
1106
- SockType :: Stream ,
1107
- SockFlag :: empty ( ) ,
1108
- SockProtocol :: Tcp ,
1109
- )
1110
- . unwrap ( ) ;
1111
- setsockopt ( & fd, KeepAlive , & true ) . unwrap ( ) ;
1112
- assert ! ( getsockopt( & fd, KeepAlive ) . unwrap( ) ) ;
1113
- }
1114
1135
}
0 commit comments