Minor network fixes.
This commit is contained in:
+4
-4
@@ -222,7 +222,7 @@ fn handle_connection_event(context: Arc<Mutex<Context>>, peers: &mut Peers, regi
|
|||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_message(stream: &mut TcpStream) -> Result<Vec<u8>, Vec<u8>> {
|
fn read_message(stream: &mut TcpStream) -> Result<Vec<u8>, ()> {
|
||||||
let instant = Instant::now();
|
let instant = Instant::now();
|
||||||
let data_size = match stream.read_u32::<BigEndian>() {
|
let data_size = match stream.read_u32::<BigEndian>() {
|
||||||
Ok(size) => { size as usize }
|
Ok(size) => { size as usize }
|
||||||
@@ -233,7 +233,7 @@ fn read_message(stream: &mut TcpStream) -> Result<Vec<u8>, Vec<u8>> {
|
|||||||
};
|
};
|
||||||
println!("Payload size is {}", data_size);
|
println!("Payload size is {}", data_size);
|
||||||
if data_size > MAX_PACKET_SIZE {
|
if data_size > MAX_PACKET_SIZE {
|
||||||
return Err(Vec::new());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buf = vec![0u8; data_size];
|
let mut buf = vec![0u8; data_size];
|
||||||
@@ -256,14 +256,14 @@ fn read_message(stream: &mut TcpStream) -> Result<Vec<u8>, Vec<u8>> {
|
|||||||
// Other errors we'll consider fatal.
|
// Other errors we'll consider fatal.
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
println!("Error reading message, only {} bytes read", bytes_read);
|
println!("Error reading message, only {} bytes read", bytes_read);
|
||||||
return Err(buf)
|
return Err(())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if buf.len() == data_size {
|
if buf.len() == data_size {
|
||||||
Ok(buf)
|
Ok(buf)
|
||||||
} else {
|
} else {
|
||||||
Err(buf)
|
Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user