净有什么区别.Dialer#KeepAlive 和 http.传输#空闲超时?


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
}

我认为保持活动状态是 tcp 连接应该保持的时间。但IdleConnTimeout似乎是一回事。那么它们之间有什么区别,如果我都设置了这些变量,tcp 连接可以保持多长时间?

术语keep-alive在两种上下文中意味着不同的东西。

net/http 传输文档使用该术语来指代持久连接。保持活动连接或持久连接是可用于多个 HTTP 事务的连接。

"Transport.IdleConnTimeout"字段指定传输在关闭连接之前在池中保留未使用的连接的时间。

网络拨号器文档使用保持活动状态术语来引用 TCP 功能来探测连接的运行状况。

Dialer.KeepAlive 字段指定将 TCP 保持活动状态探测器发送到对等方的频率。

这两个设置在堆栈中的不同层执行不同的操作。

最新更新