Retro68/gcc/libgo/go/net/main_unix_test.go

56 lines
1.3 KiB
Go
Raw Normal View History

2017-04-10 11:32:00 +00:00
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build aix || darwin || dragonfly || freebsd || hurd || linux || netbsd || openbsd || solaris
2017-04-10 11:32:00 +00:00
package net
2018-12-28 15:30:48 +00:00
import "internal/poll"
2017-04-10 11:32:00 +00:00
var (
// Placeholders for saving original socket system calls.
origSocket = socketFunc
2018-12-28 15:30:48 +00:00
origClose = poll.CloseFunc
2017-04-10 11:32:00 +00:00
origConnect = connectFunc
origListen = listenFunc
2018-12-28 15:30:48 +00:00
origAccept = poll.AcceptFunc
2017-04-10 11:32:00 +00:00
origGetsockoptInt = getsockoptIntFunc
extraTestHookInstallers []func()
extraTestHookUninstallers []func()
)
func installTestHooks() {
socketFunc = sw.Socket
2018-12-28 15:30:48 +00:00
poll.CloseFunc = sw.Close
2017-04-10 11:32:00 +00:00
connectFunc = sw.Connect
listenFunc = sw.Listen
2018-12-28 15:30:48 +00:00
poll.AcceptFunc = sw.Accept
2017-04-10 11:32:00 +00:00
getsockoptIntFunc = sw.GetsockoptInt
for _, fn := range extraTestHookInstallers {
fn()
}
}
func uninstallTestHooks() {
socketFunc = origSocket
2018-12-28 15:30:48 +00:00
poll.CloseFunc = origClose
2017-04-10 11:32:00 +00:00
connectFunc = origConnect
listenFunc = origListen
2018-12-28 15:30:48 +00:00
poll.AcceptFunc = origAccept
2017-04-10 11:32:00 +00:00
getsockoptIntFunc = origGetsockoptInt
for _, fn := range extraTestHookUninstallers {
fn()
}
}
// forceCloseSockets must be called only from TestMain.
2017-04-10 11:32:00 +00:00
func forceCloseSockets() {
for s := range sw.Sockets() {
2018-12-28 15:30:48 +00:00
poll.CloseFunc(s)
2017-04-10 11:32:00 +00:00
}
}