udp_windows.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //go:build !e2e_testing
  2. // +build !e2e_testing
  3. package udp
  4. import (
  5. "fmt"
  6. "log/slog"
  7. "net"
  8. "net/netip"
  9. "syscall"
  10. )
  11. func NewListener(l *slog.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. var conn Conn
  19. rc, err := NewRIOListener(l, ip, port)
  20. if err == nil {
  21. conn = rc
  22. } else {
  23. l.Error("Falling back to standard udp sockets", "error", err)
  24. conn, err = NewGenericListener(l, ip, port, multi, batch)
  25. if err != nil {
  26. return nil, err
  27. }
  28. }
  29. return wrapWithWDFBypass(l, conn), nil
  30. }
  31. func NewListenConfig(multi bool) net.ListenConfig {
  32. return net.ListenConfig{
  33. Control: func(network, address string, c syscall.RawConn) error {
  34. if multi {
  35. // There is no way to support multiple listeners safely on Windows:
  36. // https://docs.microsoft.com/en-us/windows/desktop/winsock/using-so-reuseaddr-and-so-exclusiveaddruse
  37. return fmt.Errorf("multiple udp listeners not supported on windows")
  38. }
  39. return nil
  40. },
  41. }
  42. }
  43. func (u *GenericConn) Rebind() error {
  44. return nil
  45. }