From f1a4db44c4c3f591df378190a6604d4547a37c25 Mon Sep 17 00:00:00 2001 From: kbleeke Date: Wed, 22 Feb 2023 13:57:40 +0100 Subject: [PATCH] Implement flush for TcpSocket --- embassy-net/src/tcp.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs index d46bd4db..b9e494fc 100644 --- a/embassy-net/src/tcp.rs +++ b/embassy-net/src/tcp.rs @@ -254,10 +254,19 @@ impl<'d> TcpIo<'d> { .await } - #[allow(unused)] async fn flush(&mut self) -> Result<(), Error> { - poll_fn(move |_| { - Poll::Ready(Ok(())) // TODO: Is there a better implementation for this? + poll_fn(move |cx| { + self.with_mut(|s, _| { + // If there are outstanding send operations, register for wake up and wait + // smoltcp issues wake-ups when octets are dequeued from the send buffer + if s.send_queue() > 0 { + s.register_send_waker(cx.waker()); + Poll::Pending + // No outstanding sends, socket is flushed + } else { + Poll::Ready(Ok(())) + } + }) }) .await }