diff --git a/cmd/verysimple/main.go b/cmd/verysimple/main.go index 80021bd..1d47e1e 100644 --- a/cmd/verysimple/main.go +++ b/cmd/verysimple/main.go @@ -241,7 +241,7 @@ func mainFunc() (result int) { return -1 } - netLayer.Prepare() + //netLayer.PrepareInterfaces() //发现有时, ipv6不是程序刚运行时就有的, 所以不应默认 预读网卡。主要是 openwrt等设备 在使用 DHCPv6 获取ipv6 等情况时。 fmt.Printf("Log Level:%d\n", utils.LogLevel) diff --git a/netLayer/dial.go b/netLayer/dial.go index 0b62cc8..78886ed 100644 --- a/netLayer/dial.go +++ b/netLayer/dial.go @@ -24,7 +24,7 @@ func (a *Addr) Dial() (net.Conn, error) { case "udp", "udp4", "udp6": ua := a.ToUDPAddr() - if !machineCanConnectToIpv6 && a.IP.To4() == nil { + if weKnowThatWeDontHaveIPV6 && a.IP.To4() == nil { return nil, ErrMachineCantConnectToIpv6 } @@ -41,7 +41,7 @@ tcp: if a.IP != nil { if a.IP.To4() == nil { - if !machineCanConnectToIpv6 { + if weKnowThatWeDontHaveIPV6 { return nil, ErrMachineCantConnectToIpv6 } else { diff --git a/netLayer/netlayer.go b/netLayer/netlayer.go index e9ff8bc..0ebd0e2 100644 --- a/netLayer/netlayer.go +++ b/netLayer/netlayer.go @@ -29,16 +29,16 @@ import ( var ( // 如果机器没有ipv6地址, 就无法联通ipv6, 此时可以在dial时更快拒绝ipv6地址, - // 避免打印过多错误输出 - machineCanConnectToIpv6 bool + // 避免打印过多错误输出. + weKnowThatWeDontHaveIPV6 bool ErrMachineCantConnectToIpv6 = errors.New("ErrMachineCanConnectToIpv6") ErrTimeout = errors.New("timeout") ) //做一些网络层的资料准备工作, 可以优化本包其它函数的调用。 -func Prepare() { - machineCanConnectToIpv6 = HasIpv6Interface() +func PrepareInterfaces() { + weKnowThatWeDontHaveIPV6 = !HasIpv6Interface() } //c.SetDeadline(time.Time{})