| 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 ( |
| 10 |
"internal/poll" |
| 11 |
"os/exec" |
| 12 |
) |
| 13 |
|
| 14 |
var ( |
| 15 |
// Placeholders for saving original socket system calls. |
| 16 |
origSocket = socketFunc |
| 17 |
origClose = poll.CloseFunc |
| 18 |
origConnect = connectFunc |
| 19 |
origListen = listenFunc |
| 20 |
origAccept = poll.AcceptFunc |
| 21 |
origGetsockoptInt = getsockoptIntFunc |
| 22 |
|
| 23 |
extraTestHookInstallers []func() |
| 24 |
extraTestHookUninstallers []func() |
| 25 |
) |
| 26 |
|
| 27 |
func installTestHooks() { |
| 28 |
socketFunc = sw.Socket |
| 29 |
poll.CloseFunc = sw.Close |
| 30 |
connectFunc = sw.Connect |
| 31 |
listenFunc = sw.Listen |
| 32 |
poll.AcceptFunc = sw.Accept |
| 33 |
getsockoptIntFunc = sw.GetsockoptInt |
| 34 |
|
| 35 |
for _, fn := range extraTestHookInstallers { |
| 36 |
fn() |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
func uninstallTestHooks() { |
| 41 |
socketFunc = origSocket |
| 42 |
poll.CloseFunc = origClose |
| 43 |
connectFunc = origConnect |
| 44 |
listenFunc = origListen |
| 45 |
poll.AcceptFunc = origAccept |
| 46 |
getsockoptIntFunc = origGetsockoptInt |
| 47 |
|
| 48 |
for _, fn := range extraTestHookUninstallers { |
| 49 |
fn() |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
// forceCloseSockets must be called only from TestMain. |
| 54 |
func forceCloseSockets() { |
| 55 |
for s := range sw.Sockets() { |
| 56 |
poll.CloseFunc(s) |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
func addCmdInheritedHandle(cmd *exec.Cmd, fd uintptr) {} |