mirror of
https://github.com/golang/go.git
synced 2025-05-06 08:03:03 +00:00
Package socktest provides utilities for socket testing. This package allows test cases in the net package to simulate complicated network conditions such as that a destination address is resolvable/discoverable but is not routable/reachable at network layer. Those conditions are required for testing functionality of timeout, multiple address families. Change-Id: Idbe32bcc3319b41b0cecac3d058014a93e13288b Reviewed-on: https://go-review.googlesource.com/6090 Reviewed-by: Ian Lance Taylor <iant@golang.org>
30 lines
763 B
Go
30 lines
763 B
Go
// 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.
|
|
|
|
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
|
|
|
|
package socktest
|
|
|
|
// Sockets maps a socket descriptor to the status of socket.
|
|
type Sockets map[int]Status
|
|
|
|
func (sw *Switch) sockso(s int) *Status {
|
|
sw.smu.RLock()
|
|
defer sw.smu.RUnlock()
|
|
so, ok := sw.sotab[s]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return &so
|
|
}
|
|
|
|
// addLocked returns a new Status without locking.
|
|
// sw.smu must be held before call.
|
|
func (sw *Switch) addLocked(s, family, sotype, proto int) *Status {
|
|
sw.once.Do(func() { switchInit(sw) })
|
|
so := Status{Cookie: cookie(family, sotype, proto)}
|
|
sw.sotab[s] = so
|
|
return &so
|
|
}
|