aboutsummaryrefslogtreecommitdiff
path: root/tun/wintun/wintun_windows.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-12-09 01:46:55 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-12-09 01:46:55 +0100
commit310ae107c346178c2d985792665dcd071ebc044b (patch)
treef44f3c7ba5c80c4eb559636fcca66697122ecdb5 /tun/wintun/wintun_windows.go
parentf64d2a2bbc915338d8c77700883466be0e2dee87 (diff)
downloadwireguard-go-310ae107c346178c2d985792665dcd071ebc044b.tar.gz
wireguard-go-310ae107c346178c2d985792665dcd071ebc044b.zip
wintun: do not load dll in init()
This prevents linking to wintun.dll until it's actually needed, which should improve startup time. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--tun/wintun/wintun_windows.go7
1 files changed, 3 insertions, 4 deletions
diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go
index e7ba8b6..afbbe76 100644
--- a/tun/wintun/wintun_windows.go
+++ b/tun/wintun/wintun_windows.go
@@ -34,7 +34,7 @@ type Adapter struct {
}
var (
- modwintun = newLazyDLL("wintun.dll")
+ modwintun = newLazyDLL("wintun.dll", setupLogger)
procWintunCreateAdapter = modwintun.NewProc("WintunCreateAdapter")
procWintunDeleteAdapter = modwintun.NewProc("WintunDeleteAdapter")
@@ -46,11 +46,10 @@ var (
procWintunGetAdapterName = modwintun.NewProc("WintunGetAdapterName")
procWintunGetRunningDriverVersion = modwintun.NewProc("WintunGetRunningDriverVersion")
procWintunSetAdapterName = modwintun.NewProc("WintunSetAdapterName")
- procWintunSetLogger = modwintun.NewProc("WintunSetLogger")
)
-func init() {
- syscall.Syscall(procWintunSetLogger.Addr(), 1, windows.NewCallback(func(level loggerLevel, msg *uint16) int {
+func setupLogger(dll *lazyDLL) {
+ syscall.Syscall(dll.NewProc("WintunSetLogger").Addr(), 1, windows.NewCallback(func(level loggerLevel, msg *uint16) int {
log.Println("[Wintun]", windows.UTF16PtrToString(msg))
return 0
}), 0, 0)