mirror of
https://github.com/golang/go
synced 2024-11-22 08:54:39 -07:00
net: consolidate the existing Windows version checks
Change-Id: I9c0ad69bd61923e9e272f157dc380a9120f08423 Reviewed-on: https://go-review.googlesource.com/c/go/+/565595 Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
parent
1cce1a6a11
commit
da5871d582
@ -5,7 +5,6 @@
|
||||
package windows
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"syscall"
|
||||
_ "unsafe"
|
||||
)
|
||||
@ -28,13 +27,3 @@ type TCP_INITIAL_RTO_PARAMETERS struct {
|
||||
Rtt uint16
|
||||
MaxSynRetransmissions uint8
|
||||
}
|
||||
|
||||
var Support_TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS = sync.OnceValue(func() bool {
|
||||
var maj, min, build uint32
|
||||
rtlGetNtVersionNumbers(&maj, &min, &build)
|
||||
return maj >= 10 && build&0xffff >= 16299
|
||||
})
|
||||
|
||||
//go:linkname rtlGetNtVersionNumbers syscall.rtlGetNtVersionNumbers
|
||||
//go:noescape
|
||||
func rtlGetNtVersionNumbers(majorVersion *uint32, minorVersion *uint32, buildNumber *uint32)
|
||||
|
@ -4,7 +4,10 @@
|
||||
|
||||
package windows
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"sync"
|
||||
_ "unsafe" // for linkname
|
||||
)
|
||||
|
||||
// Version retrieves the major, minor, and build version numbers
|
||||
// of the current Windows OS from the RtlGetNtVersionNumbers API
|
||||
@ -15,6 +18,10 @@ func Version() (major, minor, build uint32) {
|
||||
return
|
||||
}
|
||||
|
||||
//go:linkname rtlGetNtVersionNumbers syscall.rtlGetNtVersionNumbers
|
||||
//go:noescape
|
||||
func rtlGetNtVersionNumbers(majorVersion *uint32, minorVersion *uint32, buildNumber *uint32)
|
||||
|
||||
// SupportFullTCPKeepAlive indicates whether the current Windows version
|
||||
// supports the full TCP keep-alive configurations, the minimal requirement
|
||||
// is Windows 10, version 1709.
|
||||
@ -22,3 +29,18 @@ var SupportFullTCPKeepAlive = sync.OnceValue(func() bool {
|
||||
major, _, build := Version()
|
||||
return major >= 10 && build >= 16299
|
||||
})
|
||||
|
||||
// SupportTCPInitialRTONoSYNRetransmissions indicates whether the current
|
||||
// Windows version supports the TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS, the
|
||||
// minimal requirement is Windows 10.0.16299.
|
||||
var SupportTCPInitialRTONoSYNRetransmissions = sync.OnceValue(func() bool {
|
||||
major, _, build := Version()
|
||||
return major >= 10 && build >= 16299
|
||||
})
|
||||
|
||||
// SupportUnixSocket indicates whether the current Windows version supports
|
||||
// Unix Domain Sockets, the minimal requirement is Windows 10, build 17063.
|
||||
var SupportUnixSocket = sync.OnceValue(func() bool {
|
||||
major, _, build := Version()
|
||||
return major >= 10 && build >= 17063
|
||||
})
|
||||
|
@ -135,7 +135,7 @@ func (fd *netFD) connect(ctx context.Context, la, ra syscall.Sockaddr) (syscall.
|
||||
Rtt: windows.TCP_INITIAL_RTO_UNSPECIFIED_RTT, // use the default or overridden by the Administrator
|
||||
MaxSynRetransmissions: 1, // minimum possible value before Windows 10.0.16299
|
||||
}
|
||||
if windows.Support_TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS() {
|
||||
if windows.SupportTCPInitialRTONoSYNRetransmissions() {
|
||||
// In Windows 10.0.16299 TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS makes ConnectEx() fails instantly.
|
||||
params.MaxSynRetransmissions = windows.TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS
|
||||
}
|
||||
|
@ -7,34 +7,15 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"internal/syscall/windows/registry"
|
||||
"internal/syscall/windows"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func isBuild17063() bool {
|
||||
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.READ)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer k.Close()
|
||||
|
||||
s, _, err := k.GetStringValue("CurrentBuild")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
ver, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return ver >= 17063
|
||||
}
|
||||
|
||||
func skipIfUnixSocketNotSupported(t *testing.T) {
|
||||
// TODO: the isBuild17063 check should be enough, investigate why 386 and arm
|
||||
// TODO: the windows.SupportUnixSocket check should be enough, investigate why 386 and arm
|
||||
// can't run these tests on newer Windows.
|
||||
switch runtime.GOARCH {
|
||||
case "386":
|
||||
@ -42,7 +23,7 @@ func skipIfUnixSocketNotSupported(t *testing.T) {
|
||||
case "arm":
|
||||
t.Skip("not supported on windows/arm, see golang.org/issue/28061")
|
||||
}
|
||||
if !isBuild17063() {
|
||||
if !windows.SupportUnixSocket() {
|
||||
t.Skip("unix test")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user