udp_windows.go 1.2 KB

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