Source file
src/net/main_unix_test.go
1
2
3
4
5
6
7 package net
8
9 import "internal/poll"
10
11 var (
12
13 origSocket = socketFunc
14 origClose = poll.CloseFunc
15 origConnect = connectFunc
16 origListen = listenFunc
17 origAccept = poll.AcceptFunc
18 origGetsockoptInt = getsockoptIntFunc
19
20 extraTestHookInstallers []func()
21 extraTestHookUninstallers []func()
22 )
23
24 func installTestHooks() {
25 socketFunc = sw.Socket
26 poll.CloseFunc = sw.Close
27 connectFunc = sw.Connect
28 listenFunc = sw.Listen
29 poll.AcceptFunc = sw.Accept
30 getsockoptIntFunc = sw.GetsockoptInt
31
32 for _, fn := range extraTestHookInstallers {
33 fn()
34 }
35 }
36
37 func uninstallTestHooks() {
38 socketFunc = origSocket
39 poll.CloseFunc = origClose
40 connectFunc = origConnect
41 listenFunc = origListen
42 poll.AcceptFunc = origAccept
43 getsockoptIntFunc = origGetsockoptInt
44
45 for _, fn := range extraTestHookUninstallers {
46 fn()
47 }
48 }
49
50
51 func forceCloseSockets() {
52 for s := range sw.Sockets() {
53 poll.CloseFunc(s)
54 }
55 }
56
View as plain text