github.com/igoogolx/clash@v1.19.8/component/dialer/reuse_windows.go (about)

     1  package dialer
     2  
     3  import (
     4  	"net"
     5  	"syscall"
     6  
     7  	"golang.org/x/sys/windows"
     8  )
     9  
    10  func addrReuseToListenConfig(lc *net.ListenConfig) {
    11  	chain := lc.Control
    12  
    13  	lc.Control = func(network, address string, c syscall.RawConn) (err error) {
    14  		defer func() {
    15  			if err == nil && chain != nil {
    16  				err = chain(network, address, c)
    17  			}
    18  		}()
    19  
    20  		return c.Control(func(fd uintptr) {
    21  			windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_REUSEADDR, 1)
    22  		})
    23  	}
    24  }