diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-31 10:17:11 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-04-01 09:07:43 +0200 |
commit | 92f847483200a63193d55418381e685621b24e5c (patch) | |
tree | d03dec21526ee523e5364a615321ede58e3a2ec7 /tun/wintun/registryhacks_windows.go | |
parent | 2e0ed4614addc5e1842cf652c5d23779581ca7f2 (diff) |
wintun: add more retry loops
Diffstat (limited to 'tun/wintun/registryhacks_windows.go')
-rw-r--r-- | tun/wintun/registryhacks_windows.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tun/wintun/registryhacks_windows.go b/tun/wintun/registryhacks_windows.go new file mode 100644 index 0000000..62a629a --- /dev/null +++ b/tun/wintun/registryhacks_windows.go @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019 WireGuard LLC. All Rights Reserved. + */ + +package wintun + +import ( + "golang.org/x/sys/windows/registry" + "time" +) + +const ( + numRetries = 25 + retryTimeout = 100 * time.Millisecond +) + +func registryOpenKeyRetry(k registry.Key, path string, access uint32) (key registry.Key, err error) { + for i := 0; i < numRetries; i++ { + key, err = registry.OpenKey(k, path, access) + if err == nil { + break + } + if i != numRetries - 1 { + time.Sleep(retryTimeout) + } + } + return +} + +func keyGetStringValueRetry(k registry.Key, name string) (val string, valtype uint32, err error) { + for i := 0; i < numRetries; i++ { + val, valtype, err = k.GetStringValue(name) + if err == nil { + break + } + if i != numRetries - 1 { + time.Sleep(retryTimeout) + } + } + return +} |