diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-10 17:34:03 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-10 17:34:03 +0200 |
commit | 1bf1dadf15d04aae6b309abf1d2cdebadb81418c (patch) | |
tree | a1db09fa0f550e3f4969978c50c167b7fc2b81b3 | |
parent | f9dcfccbb7f918d699c0a922f3b8638c366516b4 (diff) |
wintun: poll for device key
It's actually pretty hard to guess where it is.
-rw-r--r-- | tun/wintun/wintun_windows.go | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go index 23b09d1..a73f5f2 100644 --- a/tun/wintun/wintun_windows.go +++ b/tun/wintun/wintun_windows.go @@ -294,13 +294,16 @@ func CreateInterface(description string, hwndParent uintptr) (*Wintun, bool, err // DIF_INSTALLDEVICE returns almost immediately, while the device installation // continues in the background. It might take a while, before all registry // keys and values are populated. - - // Wait for device registry key to emerge and populate. - key, err = registryEx.OpenKeyWait( - registry.LOCAL_MACHINE, - fmt.Sprintf("SYSTEM\\CurrentControlSet\\Control\\Class\\%v\\%04d", guid.ToString(&deviceClassNetGUID), deviceData.DevInst), - registry.QUERY_VALUE|registryEx.KEY_NOTIFY, - waitForRegistryTimeout) + const pollTimeout = time.Millisecond * 50 + for i := 0; i < int(waitForRegistryTimeout/pollTimeout); i++ { + if i != 0 { + time.Sleep(pollTimeout) + } + key, err = devInfoList.OpenDevRegKey(deviceData, setupapi.DICS_FLAG_GLOBAL, 0, setupapi.DIREG_DRV, registry.QUERY_VALUE|registryEx.KEY_NOTIFY) + if err == nil { + break + } + } if err == nil { _, err = registryEx.GetStringValueWait(key, "NetCfgInstanceId", waitForRegistryTimeout) if err == nil { @@ -311,8 +314,6 @@ func CreateInterface(description string, hwndParent uintptr) (*Wintun, bool, err } key.Close() } - // Clear error and let makeWintun() open the key using SetupAPI's devInfoList.OpenDevRegKey(). - err = nil } if err == nil { |