Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connected UDP sockets #36

Open
marten-seemann opened this issue May 17, 2024 · 0 comments · May be fixed by #35
Open

connected UDP sockets #36

marten-seemann opened this issue May 17, 2024 · 0 comments · May be fixed by #35

Comments

@marten-seemann
Copy link

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?

@marten-seemann marten-seemann linked a pull request May 17, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant