nal: Prevent pushing duplicate handles for the same TcpSocket

This commit is contained in:
Harry Ho 2021-03-12 12:36:30 +08:00
parent 66c3aa534f
commit 6de19f43cc
1 changed files with 4 additions and 1 deletions

View File

@ -297,7 +297,10 @@ where
let mut sockets = self.sockets.borrow_mut(); let mut sockets = self.sockets.borrow_mut();
let socket: &mut net::socket::TcpSocket = &mut *sockets.get(handle); let socket: &mut net::socket::TcpSocket = &mut *sockets.get(handle);
socket.close(); socket.close();
self.unused_handles.borrow_mut().push(handle).unwrap(); let mut unused_handles = self.unused_handles.borrow_mut();
if unused_handles.iter().find(|&x| *x == handle).is_none() {
unused_handles.push(handle).unwrap();
}
Ok(()) Ok(())
} }
} }