control_windows.go 774 B

1234567891011121314151617181920212223242526272829303132
  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. // +build windows
  7. package dialer
  8. import (
  9. "syscall"
  10. )
  11. var SupportsReusePort = true
  12. func ReusePortControl(_, _ string, c syscall.RawConn) error {
  13. var opErr error
  14. err := c.Control(func(fd uintptr) {
  15. // On Windows, SO_REUSEADDR is equivalent to SO_REUSEPORT on Linux.
  16. opErr = syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
  17. })
  18. if err != nil {
  19. l.Debugln("ReusePortControl", err)
  20. return err
  21. }
  22. if opErr != nil {
  23. l.Debugln("ReusePortControl", opErr)
  24. }
  25. return opErr
  26. }