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 flush for UDP and Raw #3432

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion embassy-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/ProfFan/smoltcp", rev="dad57e8d1cc0045f53585efe6398b19d391e72af", default-features = false, features = [
"socket",
"async",
] }
Expand Down
17 changes: 17 additions & 0 deletions embassy-net/src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<'_> {
Expand Down
17 changes: 17 additions & 0 deletions embassy-net/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down