sockopts_unix.go 736 B

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