mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 14:22:33 +00:00
Merge pull request #3437 from embassy-rs/net-flush-udp-raw
net: Add flush for UDP and Raw sockets.
This commit is contained in:
commit
4a1d189393
@ -68,7 +68,7 @@ multicast = ["smoltcp/multicast"]
|
||||
defmt = { version = "0.3", optional = true }
|
||||
log = { version = "0.4.14", optional = true }
|
||||
|
||||
smoltcp = { git="https://github.com/smoltcp-rs/smoltcp", rev="b65e1b64dc9b66fa984a2ad34e90685cb0b606de", default-features = false, features = [
|
||||
smoltcp = { git="https://github.com/smoltcp-rs/smoltcp", rev="fe0b4d102253465850cd1cf39cd33d4721a4a8d5", default-features = false, features = [
|
||||
"socket",
|
||||
"async",
|
||||
] }
|
||||
|
@ -108,6 +108,23 @@ impl<'a> RawSocket<'a> {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Flush the socket.
|
||||
///
|
||||
/// This method will wait until the socket is flushed.
|
||||
pub async fn flush(&mut self) {
|
||||
poll_fn(move |cx| {
|
||||
self.with_mut(|s, _| {
|
||||
if s.send_queue() == 0 {
|
||||
Poll::Ready(())
|
||||
} else {
|
||||
s.register_send_waker(cx.waker());
|
||||
Poll::Pending
|
||||
}
|
||||
})
|
||||
})
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for RawSocket<'_> {
|
||||
|
@ -241,6 +241,23 @@ impl<'a> UdpSocket<'a> {
|
||||
.await
|
||||
}
|
||||
|
||||
/// Flush the socket.
|
||||
///
|
||||
/// This method will wait until the socket is flushed.
|
||||
pub async fn flush(&mut self) {
|
||||
poll_fn(move |cx| {
|
||||
self.with_mut(|s, _| {
|
||||
if s.send_queue() == 0 {
|
||||
Poll::Ready(())
|
||||
} else {
|
||||
s.register_send_waker(cx.waker());
|
||||
Poll::Pending
|
||||
}
|
||||
})
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
/// Returns the local endpoint of the socket.
|
||||
pub fn endpoint(&self) -> IpListenEndpoint {
|
||||
self.with(|s, _| s.endpoint())
|
||||
|
Loading…
Reference in New Issue
Block a user