mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-23 02:01:36 +00:00
correctly clean up various things
This commit is contained in:
parent
eb8951081d
commit
f936151f2d
@ -114,7 +114,12 @@ func (intf *linkInterface) handler() error {
|
|||||||
} else {
|
} else {
|
||||||
intf.closed = make(chan struct{})
|
intf.closed = make(chan struct{})
|
||||||
intf.link.interfaces[intf.info] = intf
|
intf.link.interfaces[intf.info] = intf
|
||||||
defer close(intf.closed)
|
defer func() {
|
||||||
|
intf.link.mutex.Lock()
|
||||||
|
delete(intf.link.interfaces, intf.info)
|
||||||
|
intf.link.mutex.Unlock()
|
||||||
|
close(intf.closed)
|
||||||
|
}()
|
||||||
intf.link.core.log.Println("DEBUG: registered interface for", intf.name)
|
intf.link.core.log.Println("DEBUG: registered interface for", intf.name)
|
||||||
}
|
}
|
||||||
intf.link.mutex.Unlock()
|
intf.link.mutex.Unlock()
|
||||||
@ -144,7 +149,10 @@ func (intf *linkInterface) handler() error {
|
|||||||
timer := time.NewTimer(interval)
|
timer := time.NewTimer(interval)
|
||||||
clearTimer := func() {
|
clearTimer := func() {
|
||||||
if !timer.Stop() {
|
if !timer.Stop() {
|
||||||
<-timer.C
|
select {
|
||||||
|
case <-timer.C:
|
||||||
|
default:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defer clearTimer()
|
defer clearTimer()
|
||||||
|
@ -294,8 +294,8 @@ func (iface *tcpInterface) handler(sock net.Conn, incoming bool) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
iface.core.log.Println("DEBUG: starting handler for", name)
|
iface.core.log.Println("DEBUG: starting handler for", name)
|
||||||
link.handler()
|
err = link.handler()
|
||||||
iface.core.log.Println("DEBUG: stopped handler for", name)
|
iface.core.log.Println("DEBUG: stopped handler for", name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This exchanges/checks connection metadata, sets up the peer struct, sets up the writer goroutine, and then runs the reader within the current goroutine.
|
// This exchanges/checks connection metadata, sets up the peer struct, sets up the writer goroutine, and then runs the reader within the current goroutine.
|
||||||
|
Loading…
Reference in New Issue
Block a user