aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-net/src/tcp.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs
index 62ee5cb66..b2e3279cc 100644
--- a/embassy-net/src/tcp.rs
+++ b/embassy-net/src/tcp.rs
@@ -80,8 +80,14 @@ impl<'a> TcpReader<'a> {
80 /// Returns how many bytes were read, or an error. If no data is available, it waits 80 /// Returns how many bytes were read, or an error. If no data is available, it waits
81 /// until there is at least one byte available. 81 /// until there is at least one byte available.
82 /// 82 ///
83 /// A return value of Ok(0) means that the socket was closed and is longer able to 83 /// # Note
84 /// accept bytes or that the buffer provided is empty. 84 /// A return value of Ok(0) means that we have read all data and the remote
85 /// side has closed our receive half of the socket. The remote can no longer
86 /// send bytes.
87 ///
88 /// The send half of the socket is still open. If you want to reconnect using
89 /// the socket you split this reader off the send half needs to be closed using
90 /// [`abort()`](TcpSocket::abort).
85 pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error> { 91 pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error> {
86 self.io.read(buf).await 92 self.io.read(buf).await
87 } 93 }
@@ -277,8 +283,8 @@ impl<'a> TcpSocket<'a> {
277 /// Returns how many bytes were read, or an error. If no data is available, it waits 283 /// Returns how many bytes were read, or an error. If no data is available, it waits
278 /// until there is at least one byte available. 284 /// until there is at least one byte available.
279 /// 285 ///
280 /// A return value of Ok(0) means that the socket was closed and is longer able to 286 /// A return value of Ok(0) means that the socket was closed and is longer
281 /// accept bytes or that the buffer provided is empty. 287 /// able to receive any data.
282 pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error> { 288 pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error> {
283 self.io.read(buf).await 289 self.io.read(buf).await
284 } 290 }
@@ -303,6 +309,10 @@ impl<'a> TcpSocket<'a> {
303 /// 309 ///
304 /// If the timeout is set, the socket will be closed if no data is received for the 310 /// If the timeout is set, the socket will be closed if no data is received for the
305 /// specified duration. 311 /// specified duration.
312 ///
313 /// # Note:
314 /// Set a keep alive interval ([`set_keep_alive`] to prevent timeouts when
315 /// the remote could still respond.
306 pub fn set_timeout(&mut self, duration: Option<Duration>) { 316 pub fn set_timeout(&mut self, duration: Option<Duration>) {
307 self.io 317 self.io
308 .with_mut(|s, _| s.set_timeout(duration.map(duration_to_smoltcp))) 318 .with_mut(|s, _| s.set_timeout(duration.map(duration_to_smoltcp)))
@@ -314,6 +324,9 @@ impl<'a> TcpSocket<'a> {
314 /// the specified duration of inactivity. 324 /// the specified duration of inactivity.
315 /// 325 ///
316 /// If not set, the socket will not send keep-alive packets. 326 /// If not set, the socket will not send keep-alive packets.
327 ///
328 /// By setting a [`timeout`](Self::timeout) larger then the keep alive you
329 /// can detect a remote endpoint that no longer answers.
317 pub fn set_keep_alive(&mut self, interval: Option<Duration>) { 330 pub fn set_keep_alive(&mut self, interval: Option<Duration>) {
318 self.io 331 self.io
319 .with_mut(|s, _| s.set_keep_alive(interval.map(duration_to_smoltcp))) 332 .with_mut(|s, _| s.set_keep_alive(interval.map(duration_to_smoltcp)))