summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2018-02-22 07:08:36 -0600
committertom barrett <spalf0@gmail.com>2018-02-22 07:08:36 -0600
commit839f8a7a260276973f41a2c5a6e9d138518d7072 (patch)
tree629dec47604a83251fde775d60b57302a526683d
parentc8d308a566c9e3e5be85e0e67082a06c3420a72b (diff)
-believe found a way to tell if connection has closed
-rw-r--r--src/connection.rs10
1 files 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);
}