github.com/anacrolix/torrent@v1.61.0/sockopts_unix.go (about)

     1  //go:build !windows && !wasm
     2  
     3  package torrent
     4  
     5  import (
     6  	"syscall"
     7  
     8  	"golang.org/x/sys/unix"
     9  )
    10  
    11  func setReusePortSockOpts(fd uintptr) (err error) {
    12  	// I would use libp2p/go-reuseport to do this here, but no surprise it's
    13  	// implemented incorrectly.
    14  
    15  	// Looks like we can get away with just REUSEPORT at least on Darwin, and probably by
    16  	// extension BSDs and Linux.
    17  	if false {
    18  		err = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
    19  		if err != nil {
    20  			return
    21  		}
    22  	}
    23  	err = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1)
    24  	return
    25  }
    26  
    27  func setSockNoLinger(fd uintptr) (err error) {
    28  	return syscall.SetsockoptLinger(int(fd), syscall.SOL_SOCKET, syscall.SO_LINGER, &lingerOffVal)
    29  }
    30  
    31  func setSockIPTOS(fd uintptr, val int) (err error) {
    32  	return syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IP, syscall.IP_TOS, val)
    33  }