udp_windows.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //go:build !e2e_testing
  2. // +build !e2e_testing
  3. package udp
  4. import (
  5. "fmt"
  6. "net"
  7. "syscall"
  8. "github.com/sirupsen/logrus"
  9. )
  10. func NewListener(l *logrus.Logger, ip net.IP, port int, multi bool, batch int) (Conn, error) {
  11. if multi {
  12. //NOTE: Technically we can support it with RIO but it wouldn't be at the socket level
  13. // The udp stack would need to be reworked to hide away the implementation differences between
  14. // Windows and Linux
  15. return nil, fmt.Errorf("multiple udp listeners not supported on windows")
  16. }
  17. rc, err := NewRIOListener(l, ip, port)
  18. if err == nil {
  19. return rc, nil
  20. }
  21. l.WithError(err).Error("Falling back to standard udp sockets")
  22. return NewGenericListener(l, ip, port, multi, batch)
  23. }
  24. func NewListenConfig(multi bool) net.ListenConfig {
  25. return net.ListenConfig{
  26. Control: func(network, address string, c syscall.RawConn) error {
  27. if multi {
  28. // There is no way to support multiple listeners safely on Windows:
  29. // https://docs.microsoft.com/en-us/windows/desktop/winsock/using-so-reuseaddr-and-so-exclusiveaddruse
  30. return fmt.Errorf("multiple udp listeners not supported on windows")
  31. }
  32. return nil
  33. },
  34. }
  35. }
  36. func (u *GenericConn) Rebind() error {
  37. return nil
  38. }