Do not submit EventNoRoute repeatedly

This commit is contained in:
世界 2024-06-03 22:16:12 +08:00
parent 1c6d2891ab
commit 4efde6372e
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -42,6 +42,7 @@ type defaultInterfaceMonitor struct {
defaultInterfaceName string defaultInterfaceName string
defaultInterfaceIndex int defaultInterfaceIndex int
androidVPNEnabled bool androidVPNEnabled bool
noRoute bool
networkMonitor NetworkUpdateMonitor networkMonitor NetworkUpdateMonitor
checkUpdateTimer *time.Timer checkUpdateTimer *time.Timer
element *list.Element[NetworkUpdateCallback] element *list.Element[NetworkUpdateCallback]
@ -86,11 +87,16 @@ func (m *defaultInterfaceMonitor) postCheckUpdate() {
} }
err = m.checkUpdate() err = m.checkUpdate()
if errors.Is(err, ErrNoRoute) { if errors.Is(err, ErrNoRoute) {
if !m.noRoute {
m.noRoute = true
m.defaultInterfaceName = "" m.defaultInterfaceName = ""
m.defaultInterfaceIndex = -1 m.defaultInterfaceIndex = -1
m.emit(EventNoRoute) m.emit(EventNoRoute)
}
} else if err != nil { } else if err != nil {
m.logger.Error("check interface: ", err) m.logger.Error("check interface: ", err)
} else {
m.noRoute = false
} }
} }