switch_unix.go 790 B

1234567891011121314151617181920212223242526272829
  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. //go:build aix || darwin || dragonfly || freebsd || hurd || (js && wasm) || linux || netbsd || openbsd || solaris
  5. package socktest
  6. // Sockets maps a socket descriptor to the status of socket.
  7. type Sockets map[int]Status
  8. func (sw *Switch) sockso(s int) *Status {
  9. sw.smu.RLock()
  10. defer sw.smu.RUnlock()
  11. so, ok := sw.sotab[s]
  12. if !ok {
  13. return nil
  14. }
  15. return &so
  16. }
  17. // addLocked returns a new Status without locking.
  18. // sw.smu must be held before call.
  19. func (sw *Switch) addLocked(s, family, sotype, proto int) *Status {
  20. sw.once.Do(sw.init)
  21. so := Status{Cookie: cookie(family, sotype, proto)}
  22. sw.sotab[s] = so
  23. return &so
  24. }