i learned

master
Bel LaPointe 2023-03-22 06:57:25 -06:00
parent 26eca2e4fe
commit 2c587b8457
1 changed files with 4 additions and 2 deletions

View File

@ -134,8 +134,10 @@ impl InputEngine for InputEngineUDP {
impl InputEngineUDP {
fn _get(&mut self) -> Result<Vec<char>, std::io::Error> {
let mut buf = [0; 128];
let socket = self.last_socket.ok_or(std::io::Error::new(std::io::ErrorKind::Other, "no socket"))?;
let (amt, _) = socket.recv_from(&mut buf)?;
if !self.last_socket.is_some() {
return Ok(Vec::<char>::new());
}
let (amt, _) = self.last_socket.as_ref().unwrap().recv_from(&mut buf)?;
let buf = &mut buf[..amt];
return Ok(std::str::from_utf8(buf).unwrap().chars().collect());
}