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.
|
// 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.
|
// We don't even need to call shutdown, or use a rwcancel.
|
||||||
err3 = unix.Close(tun.routeSocket)
|
err3 = unix.Close(tun.routeSocket)
|
||||||
|
tun.routeSocket = -1
|
||||||
|
} else if tun.events != nil {
|
||||||
|
close(tun.events)
|
||||||
}
|
}
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
return err1
|
return err1
|
||||||
|
|
10
tun_linux.go
10
tun_linux.go
|
@ -357,9 +357,13 @@ func (tun *NativeTun) Events() chan TUNEvent {
|
||||||
|
|
||||||
func (tun *NativeTun) Close() error {
|
func (tun *NativeTun) Close() error {
|
||||||
var err1 error
|
var err1 error
|
||||||
close(tun.statusListenersShutdown)
|
if tun.statusListenersShutdown != nil {
|
||||||
if tun.netlinkCancel != nil {
|
close(tun.statusListenersShutdown)
|
||||||
err1 = tun.netlinkCancel.Cancel()
|
if tun.netlinkCancel != nil {
|
||||||
|
err1 = tun.netlinkCancel.Cancel()
|
||||||
|
}
|
||||||
|
} else if tun.events != nil {
|
||||||
|
close(tun.events)
|
||||||
}
|
}
|
||||||
err2 := tun.fd.Close()
|
err2 := tun.fd.Close()
|
||||||
err3 := tun.fdCancel.Cancel()
|
err3 := tun.fdCancel.Cancel()
|
||||||
|
|
Loading…
Reference in a new issue