github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/control/reuse_unix.go (about)

     1  //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
     2  
     3  package control
     4  
     5  import (
     6  	"syscall"
     7  
     8  	E "github.com/sagernet/sing/common/exceptions"
     9  
    10  	"golang.org/x/sys/unix"
    11  )
    12  
    13  func ReuseAddr() Func {
    14  	return func(network, address string, conn syscall.RawConn) error {
    15  		return Raw(conn, func(fd uintptr) error {
    16  			return E.Errors(
    17  				unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1),
    18  				unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1),
    19  			)
    20  		})
    21  	}
    22  }