aboutsummaryrefslogtreecommitdiffstats
path: root/tun/wintun/registryhacks_windows.go
blob: bbcc0207526955c5226affffcb99755dd7e3995a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 = 100
	retryTimeout = 150 * 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
}