You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if we could use connected UDP sockets. In certain cases, they're significantly faster than unconnected UDP sockets, as the kernel doesn't need to perform an address lookup.
API-wise, this is a bit tricky though. In the standard library, net.DialUDP returns a *net.UDPConn (which implements the net.PacketConn interface). However, calling WriteTo on that *net.UDPConn returns an error (even when attempting to send to the address that the connection is connected to), you have to use Write instead.
I opened #35 as a draft PR to add a DialUDP function. It's a pretty small change, and it performs the necessary syscalls to connect the socket. However, the return value is really awkward, since it's a net.PacketConn. To be able to use it, you'd first have to type-assert it to an io.Writer. It would probably cleaner to return a *UDPConn struct instead. Unfortunately, we can't use the *net.UDPConn without doing some unsafe operations.
Any advice on how to solve this?
The text was updated successfully, but these errors were encountered:
It would be nice if we could use connected UDP sockets. In certain cases, they're significantly faster than unconnected UDP sockets, as the kernel doesn't need to perform an address lookup.
API-wise, this is a bit tricky though. In the standard library,
net.DialUDP
returns a*net.UDPConn
(which implements thenet.PacketConn
interface). However, callingWriteTo
on that*net.UDPConn
returns an error (even when attempting to send to the address that the connection is connected to), you have to useWrite
instead.I opened #35 as a draft PR to add a
DialUDP
function. It's a pretty small change, and it performs the necessary syscalls to connect the socket. However, the return value is really awkward, since it's anet.PacketConn
. To be able to use it, you'd first have to type-assert it to anio.Writer
. It would probably cleaner to return a*UDPConn
struct instead. Unfortunately, we can't use the*net.UDPConn
without doing someunsafe
operations.Any advice on how to solve this?
The text was updated successfully, but these errors were encountered: