diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-09-10 21:34:11 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-09-10 21:34:11 +0000 |
| commit | aff1e7486210f6fa80627b92da5b24a1c8bf6017 (patch) | |
| tree | 18e0bf94399a12d543a2e7234cc92eb67fbda57b /embassy-net/src | |
| parent | 609b1b0355f36e4ea45e54f0b824a234d41430a5 (diff) | |
| parent | 5479647962477a794dfcde19d8e865eb47150caf (diff) | |
Merge pull request #3277 from dvdsk/main
embassy-net/read document return value Ok(0)
Diffstat (limited to 'embassy-net/src')
| -rw-r--r-- | embassy-net/src/tcp.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs index 18200287e..b2e3279cc 100644 --- a/embassy-net/src/tcp.rs +++ b/embassy-net/src/tcp.rs | |||
| @@ -79,6 +79,15 @@ impl<'a> TcpReader<'a> { | |||
| 79 | /// | 79 | /// |
| 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 | /// | ||
| 83 | /// # Note | ||
| 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). | ||
| 82 | 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> { |
| 83 | self.io.read(buf).await | 92 | self.io.read(buf).await |
| 84 | } | 93 | } |
| @@ -273,6 +282,9 @@ impl<'a> TcpSocket<'a> { | |||
| 273 | /// | 282 | /// |
| 274 | /// 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 |
| 275 | /// until there is at least one byte available. | 284 | /// until there is at least one byte available. |
| 285 | /// | ||
| 286 | /// A return value of Ok(0) means that the socket was closed and is longer | ||
| 287 | /// able to receive any data. | ||
| 276 | 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> { |
| 277 | self.io.read(buf).await | 289 | self.io.read(buf).await |
| 278 | } | 290 | } |
| @@ -297,6 +309,10 @@ impl<'a> TcpSocket<'a> { | |||
| 297 | /// | 309 | /// |
| 298 | /// 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 |
| 299 | /// 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. | ||
| 300 | pub fn set_timeout(&mut self, duration: Option<Duration>) { | 316 | pub fn set_timeout(&mut self, duration: Option<Duration>) { |
| 301 | self.io | 317 | self.io |
| 302 | .with_mut(|s, _| s.set_timeout(duration.map(duration_to_smoltcp))) | 318 | .with_mut(|s, _| s.set_timeout(duration.map(duration_to_smoltcp))) |
| @@ -308,6 +324,9 @@ impl<'a> TcpSocket<'a> { | |||
| 308 | /// the specified duration of inactivity. | 324 | /// the specified duration of inactivity. |
| 309 | /// | 325 | /// |
| 310 | /// 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. | ||
| 311 | pub fn set_keep_alive(&mut self, interval: Option<Duration>) { | 330 | pub fn set_keep_alive(&mut self, interval: Option<Duration>) { |
| 312 | self.io | 331 | self.io |
| 313 | .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))) |
