aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-net/src/tcp.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs
index 732b6d217..7babb5293 100644
--- a/embassy-net/src/tcp.rs
+++ b/embassy-net/src/tcp.rs
@@ -95,7 +95,8 @@ impl<'a> TcpWriter<'a> {
95 95
96 /// Flushes the written data to the socket. 96 /// Flushes the written data to the socket.
97 /// 97 ///
98 /// This waits until all data has been sent, and ACKed by the remote host. 98 /// This waits until all data has been sent, and ACKed by the remote host. For a connection
99 /// closed with [`abort()`](TcpSocket::abort) it will wait for the TCP RST packet to be sent.
99 pub async fn flush(&mut self) -> Result<(), Error> { 100 pub async fn flush(&mut self) -> Result<(), Error> {
100 self.io.flush().await 101 self.io.flush().await
101 } 102 }
@@ -198,7 +199,8 @@ impl<'a> TcpSocket<'a> {
198 199
199 /// Flushes the written data to the socket. 200 /// Flushes the written data to the socket.
200 /// 201 ///
201 /// This waits until all data has been sent, and ACKed by the remote host. 202 /// This waits until all data has been sent, and ACKed by the remote host. For a connection
203 /// closed with [`abort()`](TcpSocket::abort) it will wait for the TCP RST packet to be sent.
202 pub async fn flush(&mut self) -> Result<(), Error> { 204 pub async fn flush(&mut self) -> Result<(), Error> {
203 self.io.flush().await 205 self.io.flush().await
204 } 206 }
@@ -262,6 +264,11 @@ impl<'a> TcpSocket<'a> {
262 /// 264 ///
263 /// This instantly closes both the read and write halves of the socket. Any pending data 265 /// This instantly closes both the read and write halves of the socket. Any pending data
264 /// that has not been sent will be lost. 266 /// that has not been sent will be lost.
267 ///
268 /// Note that the TCP RST packet is not sent immediately - if the `TcpSocket` is dropped too soon
269 /// the remote host may not know the connection has been closed.
270 /// `abort()` callers should wait for a [`flush()`](TcpSocket::flush) call to complete before
271 /// dropping or reusing the socket.
265 pub fn abort(&mut self) { 272 pub fn abort(&mut self) {
266 self.io.with_mut(|s, _| s.abort()) 273 self.io.with_mut(|s, _| s.abort())
267 } 274 }
@@ -347,9 +354,10 @@ impl<'d> TcpIo<'d> {
347 async fn flush(&mut self) -> Result<(), Error> { 354 async fn flush(&mut self) -> Result<(), Error> {
348 poll_fn(move |cx| { 355 poll_fn(move |cx| {
349 self.with_mut(|s, _| { 356 self.with_mut(|s, _| {
357 let waiting_close = s.state() == tcp::State::Closed && s.remote_endpoint().is_some();
350 // If there are outstanding send operations, register for wake up and wait 358 // If there are outstanding send operations, register for wake up and wait
351 // smoltcp issues wake-ups when octets are dequeued from the send buffer 359 // smoltcp issues wake-ups when octets are dequeued from the send buffer
352 if s.send_queue() > 0 { 360 if s.send_queue() > 0 || waiting_close {
353 s.register_send_waker(cx.waker()); 361 s.register_send_waker(cx.waker());
354 Poll::Pending 362 Poll::Pending
355 // No outstanding sends, socket is flushed 363 // No outstanding sends, socket is flushed