diff --git a/common/network/keep_alive_go123.go b/common/network/keep_alive_go123.go index 781a700..288fbbe 100644 --- a/common/network/keep_alive_go123.go +++ b/common/network/keep_alive_go123.go @@ -7,13 +7,17 @@ import "net" type KeepAliveConfig = net.KeepAliveConfig func SetDialerTCPKeepAlive(dialer *net.Dialer, config KeepAliveConfig) { - if config.Enable { + if config.Idle < 0 && config.Interval < 0 && config.Count < 0 { + dialer.KeepAlive = -1 + } else if config.Enable { dialer.KeepAliveConfig = config } } func SetListenerTCPKeepAlive(listenConfig *net.ListenConfig, config KeepAliveConfig) { - if config.Enable { + if config.Idle < 0 && config.Interval < 0 && config.Count < 0 { + listenConfig.KeepAlive = -1 + } else if config.Enable { listenConfig.KeepAliveConfig = config } } diff --git a/common/network/sockopt.go b/common/network/sockopt.go index 4db6496..801e822 100644 --- a/common/network/sockopt.go +++ b/common/network/sockopt.go @@ -37,7 +37,7 @@ func (o *keepAliveOptions) KeepAliveConfig() (c KeepAliveConfig) { Interval: time.Duration(o.KeepAliveInterval), Count: o.KeepAliveCount, } - if c.Idle > 0 || c.Interval > 0 || c.Count > 0 { + if c.Idle != 0 || c.Interval != 0 || c.Count != 0 { c.Enable = true } return