http - net.Dialer#KeepAlive和http.Transport#IdleTimeout有什么区别?

标签 http go network-programming

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/

相关文章:

java - 从java中的http请求获取文件

python - 我可以使用带有 http-gzip 或 deflate 压缩的 python 请求库发布数据吗?

unit-testing - 如何测试不太可能发生的并发场景?

c# - 在 2 台 Windows 7 计算机上使用 C# 蓝牙发送/接收文本而无需配对

c - valgrind compains on struct sockaddr_nl

c++ - 我应该为 IOCP 创建多少个线程?

angularjs - 用angular js表达js重定向

go - 运行 dep 时出错确保 : Grouped write of manifest, 锁和 vendor :无法统计 VerifyVendor 声称存在的文件

ssl - 使用自签名证书的 TLS 连接失败

asp.net - 禁止接收 "Path ' OPTIONS。ASP.NET 网站出现异常