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