refactor: Decouple .Cleanup from ReCreateTun
The listener.Cleanup method will be called during executor.Shutdown and route.restart, so it should serve all kinds of listeners rather than a single tun device. Currently listener.ReCreateTun will call it to handle some internal affairs, This should be decoupled. In this way, the cleanup tasks for data outside the process life cycle that other listeners will add here in the future will not be accidentally triggered by configuring tun.
This commit is contained in:
parent
9feb4d6668
commit
427a377c2a
1 changed files with 6 additions and 4 deletions
|
@ -515,7 +515,6 @@ func ReCreateTun(tunConf LC.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- C.Pack
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("Start TUN listening error: %s", err.Error())
|
log.Errorln("Start TUN listening error: %s", err.Error())
|
||||||
tunConf.Enable = false
|
tunConf.Enable = false
|
||||||
Cleanup(false)
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -526,7 +525,7 @@ func ReCreateTun(tunConf LC.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- C.Pack
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Cleanup(true)
|
closeTunListener()
|
||||||
|
|
||||||
if !tunConf.Enable {
|
if !tunConf.Enable {
|
||||||
return
|
return
|
||||||
|
@ -896,10 +895,13 @@ func hasTunConfigChange(tunConf *LC.Tun) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func Cleanup(wait bool) {
|
func closeTunListener() {
|
||||||
if tunLister != nil {
|
if tunLister != nil {
|
||||||
tunLister.Close()
|
tunLister.Close()
|
||||||
tunLister = nil
|
tunLister = nil
|
||||||
}
|
}
|
||||||
LastTunConf = LC.Tun{}
|
}
|
||||||
|
|
||||||
|
func Cleanup(wait bool) {
|
||||||
|
closeTunListener()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue