libgo: update to Go 1.11
[official-gcc.git] / libgo / go / net / main_unix_test.go
blob34a8a104e82e6a161cec2d6d40073544663345e0
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.
5 // +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris
7 package net
9 import "internal/poll"
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
20 extraTestHookInstallers []func()
21 extraTestHookUninstallers []func()
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
32 for _, fn := range extraTestHookInstallers {
33 fn()
37 func uninstallTestHooks() {
38 socketFunc = origSocket
39 poll.CloseFunc = origClose
40 connectFunc = origConnect
41 listenFunc = origListen
42 poll.AcceptFunc = origAccept
43 getsockoptIntFunc = origGetsockoptInt
45 for _, fn := range extraTestHookUninstallers {
46 fn()
50 // forceCloseSockets must be called only from TestMain.
51 func forceCloseSockets() {
52 for s := range sw.Sockets() {
53 poll.CloseFunc(s)