Home | History | Annotate | Download | only in net
      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 package net
      6 
      7 import "internal/poll"
      8 
      9 var (
     10 	// Placeholders for saving original socket system calls.
     11 	origSocket      = socketFunc
     12 	origWSASocket   = wsaSocketFunc
     13 	origClosesocket = poll.CloseFunc
     14 	origConnect     = connectFunc
     15 	origConnectEx   = poll.ConnectExFunc
     16 	origListen      = listenFunc
     17 	origAccept      = poll.AcceptFunc
     18 )
     19 
     20 func installTestHooks() {
     21 	socketFunc = sw.Socket
     22 	wsaSocketFunc = sw.WSASocket
     23 	poll.CloseFunc = sw.Closesocket
     24 	connectFunc = sw.Connect
     25 	poll.ConnectExFunc = sw.ConnectEx
     26 	listenFunc = sw.Listen
     27 	poll.AcceptFunc = sw.AcceptEx
     28 }
     29 
     30 func uninstallTestHooks() {
     31 	socketFunc = origSocket
     32 	wsaSocketFunc = origWSASocket
     33 	poll.CloseFunc = origClosesocket
     34 	connectFunc = origConnect
     35 	poll.ConnectExFunc = origConnectEx
     36 	listenFunc = origListen
     37 	poll.AcceptFunc = origAccept
     38 }
     39 
     40 // forceCloseSockets must be called only from TestMain.
     41 func forceCloseSockets() {
     42 	for s := range sw.Sockets() {
     43 		poll.CloseFunc(s)
     44 	}
     45 }
     46