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
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.
The text was updated successfully, but these errors were encountered:
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)
tcp::Socket
has asend_queue()
method to check the status of tx_buffer (which can be used to implement flush), butudp::Socket
is missing any equivalent functionality to check tx_buffer status (except forcan_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 toudp::Socket
, then I could flush it just like a TCP socket before dropping.The text was updated successfully, but these errors were encountered: