From f364455c10e4ff512dd49cf80fa784fe0427d7e9 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sat, 23 Sep 2017 14:12:20 +0300 Subject: [PATCH] Cut the buffer before sending --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6bbc743..daaca2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use byteorder::{ByteOrder, NativeEndian, WriteBytesExt}; 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) @@ -36,6 +36,7 @@ fn read_body(length: u32, socket: &UdpSocket) } }, Err(e) => panic!("Read error: {}", e) + //Err(e) => {} } } @@ -47,12 +48,14 @@ fn read_udp_response(socket: &UdpSocket) Ok((length, src)) => { if valid_length(length as u32) { thread::spawn(move || { + let buf = &mut buf[..length]; let text = str::from_utf8(&buf).unwrap(); write_output(text); }); } }, - Err(e) => panic!("Read error: {}", e) + //Err(e) => panic!("Read error: {}", e) + Err(e) => {} } }