Close events channel when no status listener
This commit is contained in:
parent
7472930d4e
commit
837a12c841
@ -303,6 +303,9 @@ func (tun *NativeTun) Close() error {
|
||||
// Surprisingly, on Darwin, simply closing a route socket is enough to unblock it.
|
||||
// We don't even need to call shutdown, or use a rwcancel.
|
||||
err3 = unix.Close(tun.routeSocket)
|
||||
tun.routeSocket = -1
|
||||
} else if tun.events != nil {
|
||||
close(tun.events)
|
||||
}
|
||||
if err1 != nil {
|
||||
return err1
|
||||
|
@ -357,10 +357,14 @@ func (tun *NativeTun) Events() chan TUNEvent {
|
||||
|
||||
func (tun *NativeTun) Close() error {
|
||||
var err1 error
|
||||
if tun.statusListenersShutdown != nil {
|
||||
close(tun.statusListenersShutdown)
|
||||
if tun.netlinkCancel != nil {
|
||||
err1 = tun.netlinkCancel.Cancel()
|
||||
}
|
||||
} else if tun.events != nil {
|
||||
close(tun.events)
|
||||
}
|
||||
err2 := tun.fd.Close()
|
||||
err3 := tun.fdCancel.Cancel()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user