From ea5c35f62f07bbb6ebae8bfd33f5410eacb37cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 26 Oct 2022 19:24:08 +0800 Subject: [PATCH] Suppress no network error --- monitor_shared.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/monitor_shared.go b/monitor_shared.go index 2f89bf2..dbd18c5 100644 --- a/monitor_shared.go +++ b/monitor_shared.go @@ -63,15 +63,16 @@ type networkAddress struct { func NewDefaultInterfaceMonitor(networkMonitor NetworkUpdateMonitor, options DefaultInterfaceMonitorOptions) (DefaultInterfaceMonitor, error) { return &defaultInterfaceMonitor{ - options: options, - networkMonitor: networkMonitor, + options: options, + networkMonitor: networkMonitor, + defaultInterfaceIndex: -1, }, nil } func (m *defaultInterfaceMonitor) Start() error { err := m.checkUpdate() if err != nil { - return err + m.networkMonitor.NewError(context.Background(), err) } m.element = m.networkMonitor.RegisterCallback(m.delayCheckUpdate) return nil @@ -129,6 +130,9 @@ func (m *defaultInterfaceMonitor) DefaultInterfaceName(destination netip.Addr) s } } } + if m.defaultInterfaceIndex == -1 { + m.checkUpdate() + } return m.defaultInterfaceName } @@ -140,6 +144,9 @@ func (m *defaultInterfaceMonitor) DefaultInterfaceIndex(destination netip.Addr) } } } + if m.defaultInterfaceIndex == -1 { + m.checkUpdate() + } return m.defaultInterfaceIndex }