i learned
parent
26eca2e4fe
commit
2c587b8457
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue