@@ -61,36 +61,38 @@ pub async fn create_inbound_udp_socket(addr: &SocketAddr, ipv6_only: bool) -> io
6161
6262#[ inline]
6363fn set_tcp_keepalive ( socket : & Socket , tcp : & TcpSocketOpts ) -> io:: Result < ( ) > {
64- cfg_if ! {
65- if #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ] {
66- // FIXME: Linux Kernel doesn't support setting TCP Keep Alive.
67- // SO_KEEPALIVE works fine. But TCP_KEEPIDLE, TCP_KEEPINTV are not supported.
68- let support_tcp_keepalive_intv = !tcp. mptcp;
69- } else {
70- let support_tcp_keepalive_intv = true ;
71- }
72- }
73-
7464 if let Some ( intv) = tcp. keepalive {
7565 #[ allow( unused_mut) ]
76- let mut keepalive = TcpKeepalive :: new ( ) ;
77-
78- if support_tcp_keepalive_intv {
79- keepalive = keepalive. with_time ( intv) ;
80-
81- #[ cfg( any(
82- target_os = "freebsd" ,
83- target_os = "fuchsia" ,
84- target_os = "linux" ,
85- target_os = "netbsd" ,
86- target_vendor = "apple" ,
87- ) ) ]
88- {
89- keepalive = keepalive. with_interval ( intv) ;
90- }
66+ let mut keepalive = TcpKeepalive :: new ( ) . with_time ( intv) ;
67+
68+ #[ cfg( any(
69+ target_os = "freebsd" ,
70+ target_os = "fuchsia" ,
71+ target_os = "linux" ,
72+ target_os = "netbsd" ,
73+ target_vendor = "apple" ,
74+ ) ) ]
75+ {
76+ keepalive = keepalive. with_interval ( intv) ;
9177 }
9278
93- socket. set_tcp_keepalive ( & keepalive) ?;
79+ cfg_if ! {
80+ if #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ] {
81+ // FIXME: Linux Kernel doesn't support setting TCP Keep Alive. (MPTCP)
82+ // SO_KEEPALIVE works fine. But TCP_KEEPIDLE, TCP_KEEPINTV are not supported.
83+ // https://github.com/multipath-tcp/mptcp_net-next/issues/383
84+ // https://github.com/multipath-tcp/mptcp_net-next/issues/353
85+ if let Err ( err) = socket. set_tcp_keepalive( & keepalive) {
86+ log:: debug!( "set TCP keep-alive with time & interval failed with error: {:?}" , err) ;
87+
88+ // Try again without time & interval
89+ let keepalive = TcpKeepalive :: new( ) ;
90+ socket. set_tcp_keepalive( & keepalive) ?;
91+ }
92+ } else {
93+ socket. set_tcp_keepalive( & keepalive) ?;
94+ }
95+ }
9496 }
9597
9698 Ok ( ( ) )
0 commit comments