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