1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tcp.go 758 Bytes
一键复制 编辑 原始数据 按行查看 历史
package transport
import (
"fmt"
"net"
"time"
"github.com/elastic/beats/libbeat/logp"
)
func NetDialer(timeout time.Duration) Dialer {
return DialerFunc(func(network, address string) (net.Conn, error) {
switch network {
case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6":
default:
return nil, fmt.Errorf("unsupported network type %v", network)
}
host, port, err := net.SplitHostPort(address)
if err != nil {
return nil, err
}
addresses, err := net.LookupHost(host)
if err != nil {
logp.Warn(`DNS lookup failure "%s": %v`, host, err)
return nil, err
}
// dial via host IP by randomized iteration of known IPs
dialer := &net.Dialer{Timeout: timeout}
return dialWith(dialer, network, host, addresses, port)
})
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v5.1.2

搜索帮助