diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-02-21 21:07:10 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-02-21 21:13:10 +0100 |
| commit | 250cfa5f5f97107fc6c7b8beaa52c61c3a4423df (patch) | |
| tree | d395463592c71fec2473fc41f6ebbc35478f3ce9 /embassy-net/src | |
| parent | 88bb5984297e5a04c31f989a799df05834679b4e (diff) | |
net/tcp: fix flush() not waiting for ACK of FIN.
Diffstat (limited to 'embassy-net/src')
| -rw-r--r-- | embassy-net/src/tcp.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs index c508ff97a..57c9b7a04 100644 --- a/embassy-net/src/tcp.rs +++ b/embassy-net/src/tcp.rs | |||
| @@ -491,10 +491,16 @@ impl<'d> TcpIo<'d> { | |||
| 491 | async fn flush(&mut self) -> Result<(), Error> { | 491 | async fn flush(&mut self) -> Result<(), Error> { |
| 492 | poll_fn(move |cx| { | 492 | poll_fn(move |cx| { |
| 493 | self.with_mut(|s, _| { | 493 | self.with_mut(|s, _| { |
| 494 | let waiting_close = s.state() == tcp::State::Closed && s.remote_endpoint().is_some(); | 494 | let data_pending = s.send_queue() > 0; |
| 495 | let fin_pending = matches!( | ||
| 496 | s.state(), | ||
| 497 | tcp::State::FinWait1 | tcp::State::Closing | tcp::State::LastAck | ||
| 498 | ); | ||
| 499 | let rst_pending = s.state() == tcp::State::Closed && s.remote_endpoint().is_some(); | ||
| 500 | |||
| 495 | // If there are outstanding send operations, register for wake up and wait | 501 | // If there are outstanding send operations, register for wake up and wait |
| 496 | // smoltcp issues wake-ups when octets are dequeued from the send buffer | 502 | // smoltcp issues wake-ups when octets are dequeued from the send buffer |
| 497 | if s.send_queue() > 0 || waiting_close { | 503 | if data_pending || fin_pending || rst_pending { |
| 498 | s.register_send_waker(cx.waker()); | 504 | s.register_send_waker(cx.waker()); |
| 499 | Poll::Pending | 505 | Poll::Pending |
| 500 | // No outstanding sends, socket is flushed | 506 | // No outstanding sends, socket is flushed |
