Add timeout to socket accept (#584)

* Add timeout to socket accept

* Fix doc
This commit is contained in:
Vincent Ollivier 2024-02-25 09:48:35 +01:00 committed by GitHub
parent c923c4c6ff
commit acd213b5cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -10,6 +10,6 @@
- `CTRL` + `E` to move cursor to enf of line
- `CTRL` + `T` to move cursor to begining of file
- `CTRL` + `B` to move cursor to enf of file
- `CTRL` + `d` to cut (delete) a line
- `CTRL` + `y` to copy (yank) a line
- `CTRL` + `p` to paste (put) a line
- `CTRL` + `D` to cut (delete) a line
- `CTRL` + `Y` to copy (yank) a line
- `CTRL` + `P` to paste (put) a line

View File

@ -118,8 +118,13 @@ impl TcpSocket {
}
pub fn accept(&mut self) -> Result<IpAddress, ()> {
let timeout = 5.0;
let started = sys::clock::realtime();
if let Some((ref mut iface, ref mut device)) = *sys::net::NET.lock() {
loop {
if sys::clock::realtime() - started > timeout {
return Err(());
}
let mut sockets = SOCKETS.lock();
iface.poll(sys::net::time(), device, &mut sockets);
let socket = sockets.get_mut::<tcp::Socket>(self.handle);