Description
I've split this out of #103 as reported by @ivmarkov to keep threads disentangled:
Supporting the
bind_multiple
contract on top ofsmoltcp
seems currently impossible, or in the best case would require terrible hacks, assmoltcp
does seem to assign a source (local) address very late - only when dispatching the UDP packet. The UDP packets in the ring buffer queue however do not have any notion of "source address" before that.So it seems sending with an arbitrary local address would require us to a) wait for the UDP socket ring buffer to become empty (so that we are sure all other pending packets are sent with the "previous" local addr) b) unbind the UDP socket c) rebind the socket with the local address of the packet we want to send (NOTE: this way however we would be missing packets that we want to receive, as the
receive_from
part will now work with the local address that we want to use for sending the packet d) unbind the socket once the packet was sent e) rebind the socket again with the local address as specified inbind_multiple
What's also weird is that there is quite a bit of asymmetry wrt UDP sockets between
embedded-nal
andembedded-nal-async
.embedded-nal
is pretty simplistic, whileembedded-nal-async
seems to enforce an API which is too close to the BSD sockets one, and is not necessarily a good fit forsmoltcp
. (Not that implementingbind_multiple
is particularly easy with STD either.)I'm unsure how to proceed, honestly.
One option would be to just not support
bind_multiple
on top ofsmoltcp
by having the impl always return an error.Another would be to remove it and/or make it optional in
embedded-nal-async
.In any case, not having an impl of the UDP socket traits for
smoltcp
is an odd situation to be in, given thatsmoltcp
is the one stack used in embedded...@chrysn @lulf @Dirbaio @MabezDev Sorry for pinging. Happy to listen to your feedback / comments / guidance.
Did I miss the elephant in the room?