The comment says that KeepAlive specifies the interval:
|
// KeepAlive specifies the interval between keep-alive |
|
// probes for an active network connection. |
|
// |
|
// KeepAlive is ignored if KeepAliveConfig.Enable is true. |
|
// |
|
// If zero, keep-alive probes are sent with a default value |
|
// (currently 15 seconds), if supported by the protocol and operating |
|
// system. Network protocols or operating systems that do |
|
// not support keep-alive ignore this field. |
|
// If negative, keep-alive probes are disabled. |
|
KeepAlive time.Duration |
In fact, it is used as the idle time:
|
func newTCPConn(fd *netFD, keepAliveIdle time.Duration, keepAliveCfg KeepAliveConfig, preKeepAliveHook func(*netFD), keepAliveHook func(KeepAliveConfig)) *TCPConn { |
The KeepAlive field is passed as the second argument, which means idle instead of the interval. It is equal to the Idle field in the KeepAliveConfig:
type KeepAliveConfig struct {
// If Enable is true, keep-alive probes are enabled.
Enable bool
// Idle is the time that the connection must be idle before
// the first keep-alive probe is sent.
// If zero, a default value of 15 seconds is used.
Idle time.Duration
// Interval is the time between keep-alive probes.
// If zero, a default value of 15 seconds is used.
Interval time.Duration
// Count is the maximum number of keep-alive probes that
// can go unanswered before dropping a connection.
// If zero, a default value of 9 is used.
Count int
}
The comment says that
KeepAlive specifies the interval:go/src/net/dial.go
Lines 171 to 181 in 396a48b
In fact, it is used as
the idle time:go/src/net/tcpsock.go
Line 289 in 396a48b
The KeepAlive field is passed as the second argument, which means idle instead of the interval. It is equal to the Idle field in the KeepAliveConfig: