mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 10:47:35 +00:00
net/interfaces: quiet PAC detection logging in no-PAC case, add benchmark
This commit is contained in:
parent
38dda1ea9e
commit
cab3eb995f
@ -168,16 +168,25 @@ const (
|
|||||||
|
|
||||||
func getPACWindows() string {
|
func getPACWindows() string {
|
||||||
var res *uint16
|
var res *uint16
|
||||||
r, _, err := detectAutoProxyConfigURL.Call(
|
r, _, e := detectAutoProxyConfigURL.Call(
|
||||||
winHTTP_AUTO_DETECT_TYPE_DHCP|winHTTP_AUTO_DETECT_TYPE_DNS_A,
|
winHTTP_AUTO_DETECT_TYPE_DHCP|winHTTP_AUTO_DETECT_TYPE_DNS_A,
|
||||||
uintptr(unsafe.Pointer(&res)),
|
uintptr(unsafe.Pointer(&res)),
|
||||||
)
|
)
|
||||||
var got string
|
if r == 1 {
|
||||||
if res != nil {
|
if res == nil {
|
||||||
got = windows.UTF16PtrToString(res)
|
log.Printf("getPACWindows: unexpected success with nil result")
|
||||||
globalFree.Call(uintptr(unsafe.Pointer(res)))
|
return ""
|
||||||
} else {
|
}
|
||||||
log.Printf("getPACWindows: r=%v, err=%#v", r, err)
|
defer globalFree.Call(uintptr(unsafe.Pointer(res)))
|
||||||
|
return windows.UTF16PtrToString(res)
|
||||||
}
|
}
|
||||||
return got
|
const (
|
||||||
|
ERROR_WINHTTP_AUTODETECTION_FAILED = 12180
|
||||||
|
)
|
||||||
|
if e == syscall.Errno(ERROR_WINHTTP_AUTODETECTION_FAILED) {
|
||||||
|
// Common case on networks without advertised PAC.
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
log.Printf("getPACWindows: %T=%v", e, e) // syscall.Errno=0x....
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
17
net/interfaces/interfaces_windows_test.go
Normal file
17
net/interfaces/interfaces_windows_test.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package interfaces
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func BenchmarkGetPACWindows(b *testing.B) {
|
||||||
|
b.ReportAllocs()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
v := getPACWindows()
|
||||||
|
if i == 0 {
|
||||||
|
b.Logf("Got: %q", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user