aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-10-06 11:40:18 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-10-06 11:40:18 +0200
commit91a9b5eba54dbb5624e17da402d606d5f483b8bc (patch)
tree5d90de052dab70aea2b50fb9537b664b768a18b0
parentuapi: allow preventing creation of new peers when updating (diff)
downloadwireguard-go-jd/overlapped-nonsense.tar.xz
wireguard-go-jd/overlapped-nonsense.zip
-rw-r--r--tun/tun_windows.go10
-rw-r--r--tun/wintun/ring_windows.go18
2 files changed, 19 insertions, 9 deletions
diff --git a/tun/tun_windows.go b/tun/tun_windows.go
index 6a603a3..45f04b6 100644
--- a/tun/tun_windows.go
+++ b/tun/tun_windows.go
@@ -94,11 +94,18 @@ func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID) (Dev
return nil, fmt.Errorf("Error creating events: %v", err)
}
- tun.handle, err = tun.wt.Register(&tun.rings)
+ var errChan <-chan error
+ tun.handle, err, errChan = tun.wt.Register(&tun.rings)
if err != nil {
tun.Close()
return nil, fmt.Errorf("Error registering rings: %v", err)
}
+ go func() {
+ err := <-errChan
+ if err != nil {
+ tun.errors <- err
+ }
+ }()
return tun, nil
}
@@ -120,6 +127,7 @@ func (tun *NativeTun) Close() error {
windows.SetEvent(tun.rings.Send.TailMoved) // wake the reader if it's sleeping
}
if tun.handle != windows.InvalidHandle {
+ windows.CancelIo(tun.handle)
windows.CloseHandle(tun.handle)
}
tun.rings.Close()
diff --git a/tun/wintun/ring_windows.go b/tun/wintun/ring_windows.go
index 8f46bc9..3ee4d80 100644
--- a/tun/wintun/ring_windows.go
+++ b/tun/wintun/ring_windows.go
@@ -83,15 +83,17 @@ func (descriptor *RingDescriptor) Close() {
}
}
-func (wintun *Interface) Register(descriptor *RingDescriptor) (windows.Handle, error) {
+func (wintun *Interface) Register(descriptor *RingDescriptor) (windows.Handle, error, <-chan error) {
handle, err := wintun.handle()
if err != nil {
- return 0, err
+ windows.CloseHandle(handle)
+ return 0, err, nil
}
- var bytesReturned uint32
- err = windows.DeviceIoControl(handle, ioctlRegisterRings, (*byte)(unsafe.Pointer(descriptor)), uint32(unsafe.Sizeof(*descriptor)), nil, 0, &bytesReturned, nil)
- if err != nil {
- return 0, err
- }
- return handle, nil
+ c := make(chan error, 1)
+ go func() {
+ var bytesReturned uint32
+ c <- windows.DeviceIoControl(handle, ioctlRegisterRings, (*byte)(unsafe.Pointer(descriptor)), uint32(unsafe.Sizeof(*descriptor)), nil, 0, &bytesReturned, nil)
+ windows.CloseHandle(handle)
+ }()
+ return handle, nil, c
}