Cut the buffer before sending

This commit is contained in:
varjolintu
2017-09-23 14:12:20 +03:00
parent 95cf972f5b
commit f364455c10
+5 -2
View File
@@ -9,7 +9,7 @@ use byteorder::{ByteOrder, NativeEndian, WriteBytesExt};
fn valid_length(length: u32) -> bool fn valid_length(length: u32) -> bool
{ {
return length > 0 && length <= 4096; // 1024 ^ 2 is the maximum return length > 0 && length <= 16384; // 1024 ^ 2 is the maximum
} }
fn read_header() -> (u32) fn read_header() -> (u32)
@@ -36,6 +36,7 @@ fn read_body(length: u32, socket: &UdpSocket)
} }
}, },
Err(e) => panic!("Read error: {}", e) Err(e) => panic!("Read error: {}", e)
//Err(e) => {}
} }
} }
@@ -47,12 +48,14 @@ fn read_udp_response(socket: &UdpSocket)
Ok((length, src)) => { Ok((length, src)) => {
if valid_length(length as u32) { if valid_length(length as u32) {
thread::spawn(move || { thread::spawn(move || {
let buf = &mut buf[..length];
let text = str::from_utf8(&buf).unwrap(); let text = str::from_utf8(&buf).unwrap();
write_output(text); write_output(text);
}); });
} }
}, },
Err(e) => panic!("Read error: {}", e) //Err(e) => panic!("Read error: {}", e)
Err(e) => {}
} }
} }