This commit is contained in:
Luuk van Oijen 2023-11-23 10:59:47 +01:00
parent 04c1b76402
commit cfea87251b

View File

@ -181,13 +181,10 @@ impl Server {
socket.readable().await.expect("Failed to wait for socket to become readable!"); socket.readable().await.expect("Failed to wait for socket to become readable!");
let mut tmp = vec![0u8; 1]; let mut tmp = vec![0u8; 1];
while socket.peek(&mut tmp).await.expect("Failed to peek socket!") == 0 {
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
}
// Authentication works a little differently than normal // Authentication works a little differently than normal
// Not sure why, but the BeamMP source code shows they // Not sure why, but the BeamMP source code shows they
// also only read a single byte during authentication // also only read a single byte during authentication
socket.read_exact(&mut tmp).await.expect("Failed to read from socket!"); if socket.read_exact(&mut tmp).await.is_ok() {
let code = tmp[0]; let code = tmp[0];
match code as char { match code as char {
@ -283,15 +280,14 @@ impl Server {
tokio::task::yield_now().await; tokio::task::yield_now().await;
}, },
}; };
}
}); });
info!("Client pushed to joinset!"); info!("Client pushed to joinset!");
} }
Err(e) => error!("Failed to accept incoming connection: {:?}", e), Err(e) => error!("Failed to accept incoming connection: {:?}", e),
} }
}, },
_ = tokio::time::sleep(tokio::time::Duration::from_millis(50)) => { _ = tokio::time::sleep(tokio::time::Duration::from_millis(50)) => {},
error!("time out!");
},
} }
if set.is_empty() == false { if set.is_empty() == false {
@ -299,12 +295,8 @@ impl Server {
// Because join_next() is cancel safe, we can simply cancel it after N duration // Because join_next() is cancel safe, we can simply cancel it after N duration
// so at worst this client acceptance loop blocks for N duration // so at worst this client acceptance loop blocks for N duration
tokio::select! { tokio::select! {
_ = tokio::time::sleep(tokio::time::Duration::from_millis(10)) => { _ = set.join_next() => {},
error!("join_next timed out!"); _ = tokio::time::sleep(tokio::time::Duration::from_millis(10)) => {},
},
_ = set.join_next() => {
info!("join_next ran!");
},
} }
} }
} }