diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-26 15:57:53 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-26 16:14:32 +0100 |
commit | 2e0ed4614addc5e1842cf652c5d23779581ca7f2 (patch) | |
tree | 24c8be7eb7ea2d5418fc5fb56fcb0030c1390eb5 | |
parent | 2fa80c0cb7453ab830355b4c612192ec3064865c (diff) |
tun: windows: cancel ongoing reads on closing and delete after close
This reverts commit 52ec440d7977fad966002c3710ed9df957943407 and adds
some spice.
-rw-r--r-- | tun/tun_windows.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/tun/tun_windows.go b/tun/tun_windows.go index b7f9947..9428373 100644 --- a/tun/tun_windows.go +++ b/tun/tun_windows.go @@ -146,6 +146,7 @@ func (tun *NativeTun) closeTUN() (err error) { } t := tun.tunFileRead tun.tunFileRead = nil + windows.CancelIoEx(windows.Handle(t.Fd()), nil) err = t.Close() tun.tunLock.Unlock() break @@ -158,6 +159,7 @@ func (tun *NativeTun) closeTUN() (err error) { } t := tun.tunFileWrite tun.tunFileWrite = nil + windows.CancelIoEx(windows.Handle(t.Fd()), nil) err2 := t.Close() tun.tunLock.Unlock() if err == nil { @@ -214,13 +216,18 @@ func (tun *NativeTun) Events() chan TUNEvent { func (tun *NativeTun) Close() error { tun.close = true + err1 := tun.closeTUN() + if tun.events != nil { close(tun.events) } - /* We delete it first, before closing, so that the close operations don't hang with the concurrent read operation. */ - _, _, err := tun.wt.DeleteInterface(0) - tun.closeTUN() - return err + + _, _, err2 := tun.wt.DeleteInterface(0) + if err1 == nil { + err1 = err2 + } + + return err1 } func (tun *NativeTun) MTU() (int, error) { |