2015-10-31 01:59:47 +01: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.
|
|
|
|
|
|
|
|
package net
|
|
|
|
|
2017-09-14 19:11:35 +02:00
|
|
|
import "internal/poll"
|
|
|
|
|
2015-10-31 01:59:47 +01:00
|
|
|
var (
|
|
|
|
// Placeholders for saving original socket system calls.
|
|
|
|
origSocket = socketFunc
|
2018-01-09 02:23:08 +01:00
|
|
|
origWSASocket = wsaSocketFunc
|
2017-09-14 19:11:35 +02:00
|
|
|
origClosesocket = poll.CloseFunc
|
2015-10-31 01:59:47 +01:00
|
|
|
origConnect = connectFunc
|
2017-09-14 19:11:35 +02:00
|
|
|
origConnectEx = poll.ConnectExFunc
|
2015-10-31 01:59:47 +01:00
|
|
|
origListen = listenFunc
|
2017-09-14 19:11:35 +02:00
|
|
|
origAccept = poll.AcceptFunc
|
2015-10-31 01:59:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func installTestHooks() {
|
|
|
|
socketFunc = sw.Socket
|
2018-01-09 02:23:08 +01:00
|
|
|
wsaSocketFunc = sw.WSASocket
|
2017-09-14 19:11:35 +02:00
|
|
|
poll.CloseFunc = sw.Closesocket
|
2015-10-31 01:59:47 +01:00
|
|
|
connectFunc = sw.Connect
|
2017-09-14 19:11:35 +02:00
|
|
|
poll.ConnectExFunc = sw.ConnectEx
|
2015-10-31 01:59:47 +01:00
|
|
|
listenFunc = sw.Listen
|
2017-09-14 19:11:35 +02:00
|
|
|
poll.AcceptFunc = sw.AcceptEx
|
2015-10-31 01:59:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func uninstallTestHooks() {
|
|
|
|
socketFunc = origSocket
|
2018-01-09 02:23:08 +01:00
|
|
|
wsaSocketFunc = origWSASocket
|
2017-09-14 19:11:35 +02:00
|
|
|
poll.CloseFunc = origClosesocket
|
2015-10-31 01:59:47 +01:00
|
|
|
connectFunc = origConnect
|
2017-09-14 19:11:35 +02:00
|
|
|
poll.ConnectExFunc = origConnectEx
|
2015-10-31 01:59:47 +01:00
|
|
|
listenFunc = origListen
|
2017-09-14 19:11:35 +02:00
|
|
|
poll.AcceptFunc = origAccept
|
2015-10-31 01:59:47 +01:00
|
|
|
}
|
|
|
|
|
2016-07-22 20:15:38 +02:00
|
|
|
// forceCloseSockets must be called only from TestMain.
|
2015-10-31 01:59:47 +01:00
|
|
|
func forceCloseSockets() {
|
|
|
|
for s := range sw.Sockets() {
|
2017-09-14 19:11:35 +02:00
|
|
|
poll.CloseFunc(s)
|
2015-10-31 01:59:47 +01:00
|
|
|
}
|
|
|
|
}
|