Add tcpKeepAliveInterval in transport sockopt (#754)

Co-authored-by: Ahmad Karimi <ak12hastam@gmail.com>
Co-authored-by: Shelikhoo <xiaokangwang@outlook.com>
This commit is contained in:
yuhan6665 2021-10-12 11:39:08 -04:00 committed by GitHub
parent ef4c63812b
commit 4bb61701b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 28 deletions

View file

@ -57,6 +57,12 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
return newError("failed to set TCP_FASTOPEN_CONNECT=", tfo).Base(err)
}
}
if config.TcpKeepAliveInterval != 0 {
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, int(config.TcpKeepAliveInterval)); err != nil {
return newError("failed to set TCP_KEEPINTVL", err)
}
}
}
if config.Tproxy.IsEnabled() {
@ -81,6 +87,12 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
return newError("failed to set TCP_FASTOPEN=", tfo).Base(err)
}
}
if config.TcpKeepAliveInterval != 0 {
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, int(config.TcpKeepAliveInterval)); err != nil {
return newError("failed to set TCP_KEEPINTVL", err)
}
}
}
if config.Tproxy.IsEnabled() {