net/tcp: fix flush() not waiting for ACK of FIN.

This commit is contained in:
Dario Nieuwenhuis 2024-02-21 21:07:10 +01:00
parent 88bb598429
commit 250cfa5f5f

View file

@ -491,10 +491,16 @@ impl<'d> TcpIo<'d> {
async fn flush(&mut self) -> Result<(), Error> { async fn flush(&mut self) -> Result<(), Error> {
poll_fn(move |cx| { poll_fn(move |cx| {
self.with_mut(|s, _| { self.with_mut(|s, _| {
let waiting_close = s.state() == tcp::State::Closed && s.remote_endpoint().is_some(); let data_pending = s.send_queue() > 0;
let fin_pending = matches!(
s.state(),
tcp::State::FinWait1 | tcp::State::Closing | tcp::State::LastAck
);
let rst_pending = s.state() == tcp::State::Closed && s.remote_endpoint().is_some();
// If there are outstanding send operations, register for wake up and wait // If there are outstanding send operations, register for wake up and wait
// smoltcp issues wake-ups when octets are dequeued from the send buffer // smoltcp issues wake-ups when octets are dequeued from the send buffer
if s.send_queue() > 0 || waiting_close { if data_pending || fin_pending || rst_pending {
s.register_send_waker(cx.waker()); s.register_send_waker(cx.waker());
Poll::Pending Poll::Pending
// No outstanding sends, socket is flushed // No outstanding sends, socket is flushed