mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2024-11-22 05:59:15 +01:00
server fixes
This commit is contained in:
parent
eadb7f9f92
commit
def706884a
@ -417,7 +417,9 @@ fn server_accept_connection(
|
||||
event_callback: fn(ServerEvent),
|
||||
stream: &mut TcpStream,
|
||||
) -> Result<(), Error> {
|
||||
stream.set_nonblocking(true)?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(10)))?;
|
||||
stream.set_read_timeout(Some(Duration::from_secs(10)))?;
|
||||
|
||||
let peer = stream.peer_addr()?.to_string();
|
||||
|
||||
let mut serial_backend = new_serial_backend(port)?;
|
||||
@ -430,8 +432,11 @@ fn server_accept_connection(
|
||||
event_callback(ServerEvent::NewConnection(peer.clone()));
|
||||
|
||||
loop {
|
||||
stream.set_nonblocking(true)?;
|
||||
match stream.read_exact(&mut buffer) {
|
||||
Ok(()) => {
|
||||
stream.set_nonblocking(false)?;
|
||||
|
||||
let data_type: DataType = u32::from_be_bytes(buffer).try_into()?;
|
||||
|
||||
if !matches!(data_type, DataType::Command) {
|
||||
@ -465,6 +470,7 @@ fn server_accept_connection(
|
||||
event_callback(ServerEvent::Disconnected(peer.clone()));
|
||||
return Ok(());
|
||||
}
|
||||
stream.set_nonblocking(false)?;
|
||||
}
|
||||
}
|
||||
if let Some(response) =
|
||||
|
Loading…
Reference in New Issue
Block a user