Optimized p2p connections a bit.
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "alfis"
|
||||
version = "0.4.26"
|
||||
version = "0.4.27"
|
||||
authors = ["Revertron <alfis@revertron.com>"]
|
||||
edition = "2018"
|
||||
build = "build.rs"
|
||||
|
||||
@@ -43,5 +43,5 @@ pub const LOG_REFRESH_DELAY_SEC: u64 = 60;
|
||||
|
||||
pub const POLL_TIMEOUT: Option<Duration> = Some(Duration::from_millis(250));
|
||||
pub const MAX_PACKET_SIZE: usize = 1 * 1024 * 1024; // 1 Mb
|
||||
pub const MAX_READ_BLOCK_TIME: u128 = 500;
|
||||
pub const MAX_READ_BLOCK_TIME: u128 = 200;
|
||||
pub const MAX_NODES: usize = 15;
|
||||
|
||||
+4
-1
@@ -353,8 +353,11 @@ fn read_message(stream: &mut TcpStream) -> Result<Vec<u8>, ()> {
|
||||
}
|
||||
// Would block "errors" are the OS's way of saying that the connection is not actually ready to perform this I/O operation.
|
||||
Err(ref err) if would_block(err) => {
|
||||
// We give every connection no more than 500ms to read a message
|
||||
// We give every connection no more than 200ms to read a message
|
||||
if instant.elapsed().as_millis() < MAX_READ_BLOCK_TIME {
|
||||
// We need to sleep a bit, otherwise it can eat CPU
|
||||
let delay = Duration::from_millis(10);
|
||||
thread::sleep(delay);
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user