mirror of
https://github.com/golang/go
synced 2024-11-26 01:17:57 -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
|
package windows
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
_ "unsafe"
|
_ "unsafe"
|
||||||
)
|
)
|
||||||
@ -28,13 +27,3 @@ type TCP_INITIAL_RTO_PARAMETERS struct {
|
|||||||
Rtt uint16
|
Rtt uint16
|
||||||
MaxSynRetransmissions uint8
|
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
|
package windows
|
||||||
|
|
||||||
import "sync"
|
import (
|
||||||
|
"sync"
|
||||||
|
_ "unsafe" // for linkname
|
||||||
|
)
|
||||||
|
|
||||||
// Version retrieves the major, minor, and build version numbers
|
// Version retrieves the major, minor, and build version numbers
|
||||||
// of the current Windows OS from the RtlGetNtVersionNumbers API
|
// of the current Windows OS from the RtlGetNtVersionNumbers API
|
||||||
@ -15,6 +18,10 @@ func Version() (major, minor, build uint32) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:linkname rtlGetNtVersionNumbers syscall.rtlGetNtVersionNumbers
|
||||||
|
//go:noescape
|
||||||
|
func rtlGetNtVersionNumbers(majorVersion *uint32, minorVersion *uint32, buildNumber *uint32)
|
||||||
|
|
||||||
// SupportFullTCPKeepAlive indicates whether the current Windows version
|
// SupportFullTCPKeepAlive indicates whether the current Windows version
|
||||||
// supports the full TCP keep-alive configurations, the minimal requirement
|
// supports the full TCP keep-alive configurations, the minimal requirement
|
||||||
// is Windows 10, version 1709.
|
// is Windows 10, version 1709.
|
||||||
@ -22,3 +29,18 @@ var SupportFullTCPKeepAlive = sync.OnceValue(func() bool {
|
|||||||
major, _, build := Version()
|
major, _, build := Version()
|
||||||
return major >= 10 && build >= 16299
|
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
|
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
|
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.
|
// In Windows 10.0.16299 TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS makes ConnectEx() fails instantly.
|
||||||
params.MaxSynRetransmissions = windows.TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS
|
params.MaxSynRetransmissions = windows.TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS
|
||||||
}
|
}
|
||||||
|
@ -7,34 +7,15 @@
|
|||||||
package net
|
package net
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"internal/syscall/windows/registry"
|
"internal/syscall/windows"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
|
||||||
"testing"
|
"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) {
|
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.
|
// can't run these tests on newer Windows.
|
||||||
switch runtime.GOARCH {
|
switch runtime.GOARCH {
|
||||||
case "386":
|
case "386":
|
||||||
@ -42,7 +23,7 @@ func skipIfUnixSocketNotSupported(t *testing.T) {
|
|||||||
case "arm":
|
case "arm":
|
||||||
t.Skip("not supported on windows/arm, see golang.org/issue/28061")
|
t.Skip("not supported on windows/arm, see golang.org/issue/28061")
|
||||||
}
|
}
|
||||||
if !isBuild17063() {
|
if !windows.SupportUnixSocket() {
|
||||||
t.Skip("unix test")
|
t.Skip("unix test")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user