github.com/riscv/riscv-go@v0.0.0-20200123204226-124ebd6fcc8e/src/net/main_windows_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  package net
     6  
     7  var (
     8  	// Placeholders for saving original socket system calls.
     9  	origSocket      = socketFunc
    10  	origClosesocket = closeFunc
    11  	origConnect     = connectFunc
    12  	origConnectEx   = connectExFunc
    13  	origListen      = listenFunc
    14  	origAccept      = acceptFunc
    15  )
    16  
    17  func installTestHooks() {
    18  	socketFunc = sw.Socket
    19  	closeFunc = sw.Closesocket
    20  	connectFunc = sw.Connect
    21  	connectExFunc = sw.ConnectEx
    22  	listenFunc = sw.Listen
    23  	acceptFunc = sw.AcceptEx
    24  }
    25  
    26  func uninstallTestHooks() {
    27  	socketFunc = origSocket
    28  	closeFunc = origClosesocket
    29  	connectFunc = origConnect
    30  	connectExFunc = origConnectEx
    31  	listenFunc = origListen
    32  	acceptFunc = origAccept
    33  }
    34  
    35  // forceCloseSockets must be called only from TestMain.
    36  func forceCloseSockets() {
    37  	for s := range sw.Sockets() {
    38  		closeFunc(s)
    39  	}
    40  }