Skip to content

Commit 7c1157f

Browse files
committed
net: remove sysSocket fallback for Windows 7
`syscall.ForkLock` is not used in `syscall.StartProcess` since CL 288297, so using it in `sysSocket` makes no sense. This CL goes a little bit further and removes the `sysSocket` fallback for Windows 7, since it is not supported since go 1.21 (#57003). Updates #60942 Change-Id: If14a0d94742f1b80af994f9f69938701ee41b402 Reviewed-on: https://go-review.googlesource.com/c/go/+/506136 Reviewed-by: Heschi Kreinick <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Quim Muntal <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alex Brainman <[email protected]>
1 parent a0f816e commit 7c1157f

File tree

7 files changed

+2
-74
lines changed

7 files changed

+2
-74
lines changed

src/net/hook_windows.go

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ var (
1414
testHookDialChannel = func() { time.Sleep(time.Millisecond) } // see golang.org/issue/5349
1515

1616
// Placeholders for socket system calls.
17-
socketFunc func(int, int, int) (syscall.Handle, error) = syscall.Socket
1817
wsaSocketFunc func(int32, int32, int32, *syscall.WSAProtocolInfo, uint32, uint32) (syscall.Handle, error) = windows.WSASocket
1918
connectFunc func(syscall.Handle, syscall.Sockaddr) error = syscall.Connect
2019
listenFunc func(syscall.Handle, int) error = syscall.Listen

src/net/internal/socktest/main_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !js && !plan9 && !wasip1
5+
//go:build !js && !plan9 && !wasip1 && !windows
66

77
package socktest_test
88

src/net/internal/socktest/main_windows_test.go

-22
This file was deleted.

src/net/internal/socktest/sys_windows.go

-32
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,6 @@ import (
99
"syscall"
1010
)
1111

12-
// Socket wraps syscall.Socket.
13-
func (sw *Switch) Socket(family, sotype, proto int) (s syscall.Handle, err error) {
14-
sw.once.Do(sw.init)
15-
16-
so := &Status{Cookie: cookie(family, sotype, proto)}
17-
sw.fmu.RLock()
18-
f, _ := sw.fltab[FilterSocket]
19-
sw.fmu.RUnlock()
20-
21-
af, err := f.apply(so)
22-
if err != nil {
23-
return syscall.InvalidHandle, err
24-
}
25-
s, so.Err = syscall.Socket(family, sotype, proto)
26-
if err = af.apply(so); err != nil {
27-
if so.Err == nil {
28-
syscall.Closesocket(s)
29-
}
30-
return syscall.InvalidHandle, err
31-
}
32-
33-
sw.smu.Lock()
34-
defer sw.smu.Unlock()
35-
if so.Err != nil {
36-
sw.stats.getLocked(so.Cookie).OpenFailed++
37-
return syscall.InvalidHandle, so.Err
38-
}
39-
nso := sw.addLocked(s, family, sotype, proto)
40-
sw.stats.getLocked(nso.Cookie).Opened++
41-
return s, nil
42-
}
43-
4412
// WSASocket wraps syscall.WSASocket.
4513
func (sw *Switch) WSASocket(family, sotype, proto int32, protinfo *syscall.WSAProtocolInfo, group uint32, flags uint32) (s syscall.Handle, err error) {
4614
sw.once.Do(sw.init)

src/net/main_windows_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import "internal/poll"
88

99
var (
1010
// Placeholders for saving original socket system calls.
11-
origSocket = socketFunc
1211
origWSASocket = wsaSocketFunc
1312
origClosesocket = poll.CloseFunc
1413
origConnect = connectFunc
@@ -18,7 +17,6 @@ var (
1817
)
1918

2019
func installTestHooks() {
21-
socketFunc = sw.Socket
2220
wsaSocketFunc = sw.WSASocket
2321
poll.CloseFunc = sw.Closesocket
2422
connectFunc = sw.Connect
@@ -28,7 +26,6 @@ func installTestHooks() {
2826
}
2927

3028
func uninstallTestHooks() {
31-
socketFunc = origSocket
3229
wsaSocketFunc = origWSASocket
3330
poll.CloseFunc = origClosesocket
3431
connectFunc = origConnect

src/net/sock_windows.go

-15
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,6 @@ func maxListenerBacklog() int {
1919
func sysSocket(family, sotype, proto int) (syscall.Handle, error) {
2020
s, err := wsaSocketFunc(int32(family), int32(sotype), int32(proto),
2121
nil, 0, windows.WSA_FLAG_OVERLAPPED|windows.WSA_FLAG_NO_HANDLE_INHERIT)
22-
if err == nil {
23-
return s, nil
24-
}
25-
// WSA_FLAG_NO_HANDLE_INHERIT flag is not supported on some
26-
// old versions of Windows, see
27-
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms742212(v=vs.85).aspx
28-
// for details. Just use syscall.Socket, if windows.WSASocket failed.
29-
30-
// See ../syscall/exec_unix.go for description of ForkLock.
31-
syscall.ForkLock.RLock()
32-
s, err = socketFunc(family, sotype, proto)
33-
if err == nil {
34-
syscall.CloseOnExec(s)
35-
}
36-
syscall.ForkLock.RUnlock()
3722
if err != nil {
3823
return syscall.InvalidHandle, os.NewSyscallError("socket", err)
3924
}

src/syscall/exec_windows.go

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"unsafe"
1515
)
1616

17+
// ForkLock is not used on Windows.
1718
var ForkLock sync.RWMutex
1819

1920
// EscapeArg rewrites command line argument s as prescribed

0 commit comments

Comments
 (0)