]> Cypherpunks.ru repositories - gostls13.git/blob - src/net/main_unix_test.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / src / net / main_unix_test.go
1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build unix
6
7 package net
8
9 import "internal/poll"
10
11 var (
12         // Placeholders for saving original socket system calls.
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 // forceCloseSockets must be called only from TestMain.
51 func forceCloseSockets() {
52         for s := range sw.Sockets() {
53                 poll.CloseFunc(s)
54         }
55 }