github.com/containers/podman/v4@v4.9.4/pkg/machine/ports_windows.go (about)

     1  package machine
     2  
     3  import (
     4  	"net"
     5  	"syscall"
     6  )
     7  
     8  // NOTE the reason for the code duplication between win and unix is that the syscall
     9  // implementations require a different cast (Handle on Windows, int on Unixes)
    10  func getPortCheckListenConfig() *net.ListenConfig {
    11  	return &net.ListenConfig{
    12  		Control: func(network, address string, c syscall.RawConn) (cerr error) {
    13  			if err := c.Control(func(fd uintptr) {
    14  				// Prevent listening socket from holding over in TIME_WAIT in the rare case a connection
    15  				// attempt occurs in the short window the socket is listening. This ensures the registration
    16  				// will be gone when close() completes, freeing it up for the real subsequent listen by another
    17  				// process
    18  				cerr = syscall.SetsockoptLinger(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_LINGER, &syscall.Linger{
    19  					Onoff:  1,
    20  					Linger: 0,
    21  				})
    22  			}); err != nil {
    23  				cerr = err
    24  			}
    25  			return
    26  		},
    27  	}
    28  }