diff --git a/src/main.rs b/src/main.rs index b82f0eb..4db0271 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ use std::sync::mpsc::{SyncSender,Receiver}; use chrono::Local; use std::fs; use std::fmt; +use std::time; use serde::{Serialize, Deserialize}; enum ToClientTCPMessageType { LoggedIn = 0, @@ -568,7 +569,7 @@ fn client_read_thread(mut stream: TcpStream, mut client: Arc) { let mut read_buf:[u8;1] = [0; 1]; //messages come through as a 1 byte type identifier, that can be one of 0 (login) 1 (get rooms), 2 (join/leave room) 3 (send message to room), 4 (send message to room including me), 5 (send message to group), 6 (establish group) loop { - + //read exactly 1 byte stream.read_exact(&mut read_buf).unwrap(); //println!("Got a message {}",read_buf[0]); @@ -617,6 +618,7 @@ fn client_write_thread(mut stream: TcpStream, rx: Receiver> ) { fn handle_client(stream: TcpStream, client_id: u32, clients_mutex: Arc>>>, rooms_mutex: Arc>>>){ stream.set_nodelay(true).unwrap(); + stream.set_read_timeout(Some(time::Duration::new(10,0))).unwrap(); println!("{}: Accepted new connection, assigned client id {}",Local::now().format("%Y-%m-%d %H:%M:%S"),client_id); let (tx, rx) = mpsc::sync_channel(10000);