type Dialer struct {
......
// KeepAlive specifies the keep-alive period for an active
// network connection.
// If zero, keep-alives are enabled if supported by the protocol
// and operating system. Network protocols or operating systems
// that do not support keep-alives ignore this field.
// If negative, keep-alives are disabled.
KeepAlive time.Duration
}
type Transport struct {
......
// IdleConnTimeout is the maximum amount of time an idle
// (keep-alive) connection will remain idle before closing
// itself.
// Zero means no limit.
IdleConnTimeout time.Duration
}
我认为keep-alive是tcp连接应保持的时间。但是IdleConnTimeout似乎是同一回事。那么它们之间有什么区别,如果我都设置了这些变量,则tcp连接可以保持多长时间?]
术语“保持活动”在两种情况下意味着不同的事物。
net / http传输文档使用该术语来指代persistent connections。保持活动连接或持久连接是可以用于多个HTTP事务的连接。
Transport.IdleConnTimeout字段指定传输在关闭连接之前将未使用的连接保留在池中的时间。
网络拨号程序文档使用保持活动术语来指代TCP feature for probing the health of a connection。
[Dialer.KeepAlive字段指定将TCP保持活动状态的探测发送到对等体的频率。
这两个设置在堆栈的不同层上执行不同的操作。