control_windows.go 793 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright (C) 2019 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. //go:build windows
  7. // +build windows
  8. package dialer
  9. import (
  10. "syscall"
  11. )
  12. var SupportsReusePort = true
  13. func ReusePortControl(_, _ string, c syscall.RawConn) error {
  14. var opErr error
  15. err := c.Control(func(fd uintptr) {
  16. // On Windows, SO_REUSEADDR is equivalent to SO_REUSEPORT on Linux.
  17. opErr = syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
  18. })
  19. if err != nil {
  20. l.Debugln("ReusePortControl", err)
  21. return err
  22. }
  23. if opErr != nil {
  24. l.Debugln("ReusePortControl", opErr)
  25. }
  26. return opErr
  27. }