Skip to content

Commit

Permalink
Do not submit EventNoRoute repeatedly
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Jun 6, 2024
1 parent 1c6d289 commit 4efde63
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions monitor_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type defaultInterfaceMonitor struct {
defaultInterfaceName string
defaultInterfaceIndex int
androidVPNEnabled bool
noRoute bool
networkMonitor NetworkUpdateMonitor
checkUpdateTimer *time.Timer
element *list.Element[NetworkUpdateCallback]
Expand Down Expand Up @@ -86,11 +87,16 @@ func (m *defaultInterfaceMonitor) postCheckUpdate() {
}
err = m.checkUpdate()
if errors.Is(err, ErrNoRoute) {
m.defaultInterfaceName = ""
m.defaultInterfaceIndex = -1
m.emit(EventNoRoute)
if !m.noRoute {
m.noRoute = true
m.defaultInterfaceName = ""
m.defaultInterfaceIndex = -1
m.emit(EventNoRoute)
}
} else if err != nil {
m.logger.Error("check interface: ", err)
} else {
m.noRoute = false
}
}

Expand Down

0 comments on commit 4efde63

Please sign in to comment.