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连接可以保持多长时间?
最佳答案
保持 Activity 一词在两种情况下表示不同的事物。
net / http Transport文档使用该术语来引用persistent connections。保持 Activity 连接或持久连接是可以用于多个HTTP事务的连接。
Transport.IdleConnTimeout字段指定传输在关闭连接之前将未使用的连接保留在池中的时间。
网络Dialer文档使用keep-alive术语来引用TCP feature for probing the health of a connection。
Dialer.KeepAlive字段指定将TCP保持 Activity 状态探测发送到对等方的频率。
这两个设置在堆栈的不同层执行不同的操作。
关于http - net.Dialer#KeepAlive和http.Transport#IdleTimeout有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59656164/