From 839f8a7a260276973f41a2c5a6e9d138518d7072 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Thu, 22 Feb 2018 07:08:36 -0600 Subject: -believe found a way to tell if connection has closed --- src/connection.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/connection.rs b/src/connection.rs index b84c4e8..5c086fa 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -67,16 +67,20 @@ impl Connection { let mut location = masses[self.index].get_location(); let mut data = String::new(); match self.buff_r.read_line(&mut data) { - Ok(_result) => match data.as_bytes() { + Ok(result) => match data.as_bytes() { b"5\n" => location.0 += 1, b"0\n" => location.0 -= 1, b"8\n" => location.1 += 1, b"2\n" => location.1 -= 1, b"4\n" => location.2 += 1, b"6\n" => location.2 -= 1, - _ => (), + _ => { + if result == 0 { + self.open = false; + } + }, }, - Err(_error) => println!("b{}", _error) + Err(_error) => (), } masses[self.index].give_location(location); } -- cgit v1.2.3