mirror of
https://github.com/tailscale/tailscale.git
synced 2026-04-09 00:48:00 -04:00
We used to create a net.UDPConn by calling (*net.ListenConfig).ListenPacket, then conditionally upgrade it to a batching.Conn on platforms that support it. This works on Linux, where we can upgrade an existing net.UDPConn to support batching I/O, but it does not work as well on other platforms where batching may need to be implemented in terms of a platform-specific APIs. Also, since in practice all nettype.PacketConn implementations were net.UDPConn (at least temporarily before the upgrade), we used type assertions to *net.UDPConn even when any syscall.Conn (a type with a SyscallConn method) would work. In this PR, as preparation for implementing batching.Conn for Windows, we replace those type assertions with interfaces and add batching.PacketListener. The default implementation creates a net.UDPConn and tries to upgrade it to a batching.Conn, while allowing platforms to override ListenPacket as needed. We then unexport batching.TryUpgradeToConn and replace its usage with batching.PacketListener. Updates tailscale/corp#36208