Source file src/net/internal/socktest/switch_unix.go

     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  //go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris
     6  
     7  package socktest
     8  
     9  // Sockets maps a socket descriptor to the status of socket.
    10  type Sockets map[int]Status
    11  
    12  func (sw *Switch) sockso(s int) *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.
    24  func (sw *Switch) addLocked(s, 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  

View as plain text