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
5package socktest
6
7import "syscall"
8
9// Sockets maps a socket descriptor to the status of socket.
10type Sockets map[syscall.Handle]Status
11
12func (sw *Switch) sockso(s syscall.Handle) *Status {
13	sw.smu.RLock()
14	defer sw.smu.RUnlock()
15	so, ok := sw.sotab[s]
16	if !ok {
17		return nil
18	}
19	return &so
20}
21
22// addLocked returns a new Status without locking.
23// sw.smu must be held before call.
24func (sw *Switch) addLocked(s syscall.Handle, family, sotype, proto int) *Status {
25	sw.once.Do(sw.init)
26	so := Status{Cookie: cookie(family, sotype, proto)}
27	sw.sotab[s] = so
28	return &so
29}
30