switch_windows.go 730 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. package socktest
  5. import "syscall"
  6. // Sockets maps a socket descriptor to the status of socket.
  7. type Sockets map[syscall.Handle]Status
  8. func (sw *Switch) sockso(s syscall.Handle) *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 syscall.Handle, 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. }