mihomo/common/net/tcp_keepalive_go123.go

20 lines
482 B
Go
Raw Normal View History

//go:build go1.23
package net
import "net"
2024-08-14 13:01:06 +08:00
func tcpKeepAlive(tcp *net.TCPConn) {
config := net.KeepAliveConfig{
Enable: true,
Idle: KeepAliveIdle,
Interval: KeepAliveInterval,
}
2024-08-14 13:01:06 +08:00
if !SupportTCPKeepAliveCount() {
// it's recommended to set both Idle and Interval to non-negative values in conjunction with a -1
// for Count on those old Windows if you intend to customize the TCP keep-alive settings.
config.Count = -1
}
_ = tcp.SetKeepAliveConfig(config)
}