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 7package net 8 9import "internal/poll" 10 11var ( 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 24func 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 37func 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. 51func forceCloseSockets() { 52 for s := range sw.Sockets() { 53 poll.CloseFunc(s) 54 } 55} 56