Source file
src/net/main_windows_test.go
1
2
3
4
5 package net
6
7 import (
8 "internal/poll"
9 "os/exec"
10 "syscall"
11 )
12
13 var (
14
15 origWSASocket = wsaSocketFunc
16 origClosesocket = poll.CloseFunc
17 origConnect = connectFunc
18 origConnectEx = poll.ConnectExFunc
19 origListen = listenFunc
20 origAccept = poll.AcceptFunc
21 )
22
23 func installTestHooks() {
24 wsaSocketFunc = sw.WSASocket
25 poll.CloseFunc = sw.Closesocket
26 connectFunc = sw.Connect
27 poll.ConnectExFunc = sw.ConnectEx
28 listenFunc = sw.Listen
29 poll.AcceptFunc = sw.AcceptEx
30 }
31
32 func uninstallTestHooks() {
33 wsaSocketFunc = origWSASocket
34 poll.CloseFunc = origClosesocket
35 connectFunc = origConnect
36 poll.ConnectExFunc = origConnectEx
37 listenFunc = origListen
38 poll.AcceptFunc = origAccept
39 }
40
41
42 func forceCloseSockets() {
43 for s := range sw.Sockets() {
44 poll.CloseFunc(s)
45 }
46 }
47
48 func addCmdInheritedHandle(cmd *exec.Cmd, fd uintptr) {
49
50
51
52
53 if cmd.SysProcAttr == nil {
54 cmd.SysProcAttr = &syscall.SysProcAttr{}
55 }
56 cmd.SysProcAttr.AdditionalInheritedHandles = append(cmd.SysProcAttr.AdditionalInheritedHandles, syscall.Handle(fd))
57 }
58
View as plain text