Documentation
¶
Overview ¶
Package conn 提供连接管理相关的工具。
Index ¶
Constants ¶
View Source
const DefaultDialTimeout = 10 * time.Second
DefaultDialTimeout 是 NewDefaultManager 拨号超时(#77)。
裸 net.Dial 没有超时:对黑 hole 对端(SYN 有去无回的端口),每次拨号 会挂在操作系统自己的超时上——macOS 上是 75 秒(同仓 sshx/dial.go 对 connectTimeout 的论证原文)。作为「自动重连」组件,退化形态是每次重连 假死 75s+:连接数虽少,可用性长时间为零。10s 与 sshx.DefaultConnectTimeout 同量级:远大于正常建连 RT,又把最坏情况压回一个重连周期内。
Variables ¶
ErrConnectionUnavailable 在连接不可用时由 Write 方法返回。
Functions ¶
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 管理一个 net.Conn 的生命周期。
通过 Take 获取连接,通过 Put 报告错误。 当 Put 收到非 nil error 时,当前连接失效,Manager 自动重连(指数退避)。
func NewDefaultManager ¶
NewDefaultManager 创建一个使用默认配置的连接管理器。 拨号带 DefaultDialTimeout 超时(#77),重连退避用 time.After。
func NewManager ¶
NewManager 创建一个连接管理器。
参数:
- d: 连接创建函数
- network/address: 传递给 Dialer
- after: 时间控制函数(测试可注入,生产用 time.After)
Click to show internal directories.
Click to hide internal directories.