diff options
Diffstat (limited to 'src/bin/server.rs')
-rw-r--r-- | src/bin/server.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/bin/server.rs b/src/bin/server.rs index 71541f8..871315e 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -1,24 +1,27 @@ -use std::io::prelude::*; -use std::net::{TcpListener, TcpStream}; +use std::thread::sleep; +use std::time::Duration; +use std::net::TcpListener; extern crate space; use space::connection::Connection; fn main() { let listener = TcpListener::bind("localhost:6000").unwrap(); - listener.set_nonblocking(true); + listener.set_nonblocking(true).unwrap(); let mut connections = Vec::new(); - loop { - for stream in listener.incoming() { - match stream { - Ok(stream) => connections.push(Connection::new(stream)), - _ => (), + for stream in listener.incoming() { + match stream { + Ok(stream) => connections.push(Connection::new(stream)), + _ => { + println!("looped"); + for i in 0..connections.len() { + connections[i].process(); + } + connections.retain(|connection| connection.open ); + sleep(Duration::from_millis(100)); } - for i in 0..connections.len() { - connections[i].process(); - } - connections.retain(|connection| connection.open ); } } + } |