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

add send_queue() for udp::Socket? #838

Open
phire opened this issue Aug 26, 2023 · 1 comment
Open

add send_queue() for udp::Socket? #838

phire opened this issue Aug 26, 2023 · 1 comment

Comments

@phire
Copy link

phire commented Aug 26, 2023

tcp::Socket has a send_queue() method to check the status of tx_buffer (which can be used to implement flush), but udp::Socket is missing any equivalent functionality to check tx_buffer status (except for can_send)

My usecase:
I want to create a UDP socket, send a packet to a broadcast address, and then immediately destroy the socket. The same memory is reused to create TCP socket and listen for an incoming connection. This loops after a timeout, destroying the TCP socket to reuse the memory for a UDP socket.

There is no sane way to implement this with the current api, as dropping or closing the UDP socket too soon drops any unsent packets before they even reach the network driver. Yes, I know that delivery of UDP packets isn't meant to be reliable, but this results in zero packets being delivered.
The only workaround is to insert a sleep before destroying the UDP socket and hope it's the delay is long enough to allow for transmission, but I'd rather not do that.

If send_queue() was added to udp::Socket, then I could flush it just like a TCP socket before dropping.

@Dirbaio
Copy link
Member

Dirbaio commented Aug 26, 2023

if it's a single packet, you can kinda already do it: set the buffer size to 1 packet, then wait until can_send() == true.

I agree having send_queue/recv_queue would be nice, it helps if you want to flush more than 1 packet. PRs welcome! (If you do, please add it to IcmpSocket, RawSocket as well, as they should be consistent)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants