From 7094849bf164ff6f853c8f6812a0e831a66762f3 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Thu, 14 Jun 2018 10:18:22 -0500 Subject: updated dependancies, made it so server still processes events if client connection is disconnected --- src/bin/server.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/bin') diff --git a/src/bin/server.rs b/src/bin/server.rs index 1fad1d3..e20acf6 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -25,22 +25,31 @@ fn main() { let mut masses = populate(); - let mut connections = Vec::new(); + let mut connections : Vec = Vec::new(); for stream in listener.incoming() { match stream { - Ok(stream) => connections.push(ServerConnection::new(stream, &mut masses)), + Ok(stream) => { + let new_connection = ServerConnection::new(stream, &mut masses); + let exists = connections.iter().position(|connection| + connection.name == new_connection.name && + connection.module_type == new_connection.module_type); + match exists { + Some(index) => { connections.remove(index); }, + _ => (), + } + connections.push(new_connection); + }, _ => { for i in 0..connections.len() { connections[i].process(&mut masses); } - connections.retain(|connection| connection.open); for mass in masses.values_mut() { mass.process(); } sleep(Duration::from_millis(100)); - } + }, } } } -- cgit v1.2.3