1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tcp.go 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
package transport
import (
"fmt"
"net"
"strings"
"time"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/testing"
)
func NetDialer(timeout time.Duration) Dialer {
return TestNetDialer(testing.NullDriver, timeout)
}
func TestNetDialer(d testing.Driver, timeout time.Duration) Dialer {
return DialerFunc(func(network, address string) (net.Conn, error) {
switch network {
case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6":
default:
d.Fatal("network type", fmt.Errorf("unsupported network type %v", network))
return nil, fmt.Errorf("unsupported network type %v", network)
}
host, port, err := net.SplitHostPort(address)
d.Fatal("parse host", err)
if err != nil {
return nil, err
}
addresses, err := net.LookupHost(host)
d.Fatal("dns lookup", err)
d.Info("addresses", strings.Join(addresses, ", "))
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/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v6.0.0-beta2

搜索帮助

0d507c66 1850385 C8b1a773 1850385