Skip to content

Commit

Permalink
fix: Allow to disable keep alive
Browse files Browse the repository at this point in the history
  • Loading branch information
layou233 committed Aug 23, 2024
1 parent ae0d78b commit 0bb3c52
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions common/network/keep_alive_go123.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion common/network/sockopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0bb3c52

Please sign in to comment.