github.com/mdempsky/go@v0.0.0-20151201204031-5dd372bd1e70/src/net/main_unix_test.go (about) 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 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris 6 7 package net 8 9 var ( 10 // Placeholders for saving original socket system calls. 11 origSocket = socketFunc 12 origClose = closeFunc 13 origConnect = connectFunc 14 origListen = listenFunc 15 origAccept = acceptFunc 16 origGetsockoptInt = getsockoptIntFunc 17 18 extraTestHookInstallers []func() 19 extraTestHookUninstallers []func() 20 ) 21 22 func installTestHooks() { 23 socketFunc = sw.Socket 24 closeFunc = sw.Close 25 connectFunc = sw.Connect 26 listenFunc = sw.Listen 27 acceptFunc = sw.Accept 28 getsockoptIntFunc = sw.GetsockoptInt 29 30 for _, fn := range extraTestHookInstallers { 31 fn() 32 } 33 } 34 35 func uninstallTestHooks() { 36 socketFunc = origSocket 37 closeFunc = origClose 38 connectFunc = origConnect 39 listenFunc = origListen 40 acceptFunc = origAccept 41 getsockoptIntFunc = origGetsockoptInt 42 43 for _, fn := range extraTestHookUninstallers { 44 fn() 45 } 46 } 47 48 func forceCloseSockets() { 49 for s := range sw.Sockets() { 50 closeFunc(s) 51 } 52 }