quinn icon indicating copy to clipboard operation
quinn copied to clipboard

feat: use mutable transmits to AsyncUdpSocket::poll_send

Open dignifiedquire opened this issue 2 years ago • 6 comments

In our implementation (n0-computer/iroh) we currently have to maniuplate the destination addresses based on internal mappings. Currently we need to copy the full Transmit slice in order to update these addresses. To avoid this copy, this changes it such that a mutable reference is passed in.

dignifiedquire avatar Oct 19 '23 08:10 dignifiedquire

What happens when a poll_send call isn't able to transmit all packets immediately, i.e. returns less than transmits.len()? It seems difficult to avoid unpredictably double-translating addresses with this change, which could be harmful if your translation isn't idempotent.

Ralith avatar Oct 20 '23 01:10 Ralith

That should be easy enough to handle on our side, we can either reset to the original addrs for those that weren't sent, or detect based on the addr if we have mapped it yet.

dignifiedquire avatar Oct 20 '23 08:10 dignifiedquire

The CI failures look unrelated to me: BSD seems to hang and the lint is complaining about unrelated code.

dignifiedquire avatar Oct 20 '23 08:10 dignifiedquire

this would be useful for us too (for address mangling as well)

chayleaf avatar Nov 24 '23 01:11 chayleaf

I'd like to at least see a clearly documented contract for whether or not unsent entries may be changed after the call returns. I think it should specifically guarantee that they won't be to avoid unpredictable behavior. It's not clear to me if that guarantee can be respected without defeating the point by requiring storage on the side, though.

Is this copy showing up in profiling at all? It should be straightforward to reuse an allocation for it.

Ralith avatar Nov 25 '23 00:11 Ralith

https://github.com/quinn-rs/quinn/pull/1729 will likely render this unnecessary by only accepting a single, trivially rewritten Transmit at a time.

Ralith avatar Dec 21 '23 03:12 Ralith

Closing in favor of #1729

dignifiedquire avatar Apr 17 '24 19:04 dignifiedquire