2024-08-14 11:51:39 +08:00
|
|
|
//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 11:51:39 +08:00
|
|
|
}
|
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)
|
2024-08-14 11:51:39 +08:00
|
|
|
}
|