added timeout

main
Kyle Johnsen 2022-02-21 18:24:08 -05:00
parent c2a30171e3
commit de78812fbb
1 changed files with 3 additions and 1 deletions

View File

@ -11,6 +11,7 @@ use std::sync::mpsc::{SyncSender,Receiver};
use chrono::Local; use chrono::Local;
use std::fs; use std::fs;
use std::fmt; use std::fmt;
use std::time;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
enum ToClientTCPMessageType { enum ToClientTCPMessageType {
LoggedIn = 0, LoggedIn = 0,
@ -617,6 +618,7 @@ fn client_write_thread(mut stream: TcpStream, rx: Receiver<Vec<u8>> ) {
fn handle_client(stream: TcpStream, client_id: u32, clients_mutex: Arc<RwLock<HashMap<u32,Arc<Client>>>>, rooms_mutex: Arc<RwLock<HashMap<String,Arc<Room>>>>){ fn handle_client(stream: TcpStream, client_id: u32, clients_mutex: Arc<RwLock<HashMap<u32,Arc<Client>>>>, rooms_mutex: Arc<RwLock<HashMap<String,Arc<Room>>>>){
stream.set_nodelay(true).unwrap(); 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); 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); let (tx, rx) = mpsc::sync_channel(10000);