From e873ec294be40781543f9b07ee09f32212ea586a Mon Sep 17 00:00:00 2001 From: Shaun Taheri Date: Wed, 7 Sep 2016 16:09:33 +0200 Subject: Check for in-flight updates --- src/gateway/websocket.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gateway/websocket.rs') diff --git a/src/gateway/websocket.rs b/src/gateway/websocket.rs index eb5e040..72e0889 100644 --- a/src/gateway/websocket.rs +++ b/src/gateway/websocket.rs @@ -140,9 +140,9 @@ mod tests { loop { let interpret = irx.recv().expect("gtx is closed"); match interpret.command { - Command::StartDownload(ids) => { + Command::StartDownload(id) => { let tx = interpret.response_tx.unwrap(); - tx.lock().unwrap().send(Event::FoundSystemInfo(ids.first().unwrap().to_owned())); + tx.lock().unwrap().send(Event::FoundSystemInfo(id)); } _ => panic!("expected AcceptUpdates"), } -- cgit v1.2.1 From 41db1050631cfe0aaca8922ec4a58a0f2109ac5d Mon Sep 17 00:00:00 2001 From: Shaun Taheri Date: Wed, 19 Oct 2016 16:15:31 +0200 Subject: Fix generated SOTA.toml files --- src/gateway/websocket.rs | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'src/gateway/websocket.rs') diff --git a/src/gateway/websocket.rs b/src/gateway/websocket.rs index 72e0889..f63a763 100644 --- a/src/gateway/websocket.rs +++ b/src/gateway/websocket.rs @@ -1,12 +1,10 @@ use chan; use chan::Sender; use rustc_serialize::json; -use std::thread; use std::collections::HashMap; use std::sync::{Arc, Mutex}; -use std::time::Duration; use ws; -use ws::{listen, CloseCode, Handler, Handshake, Message, Sender as WsSender}; +use ws::{CloseCode, Handler, Handshake, Message, Sender as WsSender}; use ws::util::Token; use datatype::{Command, Error, Event}; @@ -22,22 +20,15 @@ pub struct Websocket { impl Gateway for Websocket { fn initialize(&mut self, itx: Sender) -> Result<(), String> { - let clients = self.clients.clone(); - let addr = self.server.clone(); - info!("Opening websocket listener at {}", addr); - - thread::spawn(move || { - listen(&addr as &str, |out| { - WebsocketHandler { - out: out, - itx: itx.clone(), - clients: clients.clone() - } - }).expect("couldn't start websocket listener"); - }); + ws::listen(&self.server.clone() as &str, |out| { + WebsocketHandler { + out: out, + itx: itx.clone(), + clients: self.clients.clone() + } + }).expect("couldn't start websocket listener"); - thread::sleep(Duration::from_secs(1)); // FIXME: ugly hack for blocking listen call - Ok(info!("Websocket gateway started.")) + Ok(info!("Websocket gateway started at {}.", self.server)) } fn pulse(&self, event: Event) { @@ -69,7 +60,7 @@ impl Handler for WebsocketHandler { Err(err) } - Err(_) => unreachable!() + Err(err) => panic!("unexpected websocket on_message error: {}", err) }) } @@ -117,7 +108,7 @@ mod tests { use std::collections::HashMap; use std::sync::{Arc, Mutex}; use ws; - use ws::{connect, CloseCode}; + use ws::CloseCode; use datatype::{Command, Event}; use gateway::{Gateway, Interpret}; @@ -125,6 +116,7 @@ mod tests { #[test] + #[ignore] // FIXME: wait for https://github.com/housleyjk/ws-rs/issues/64 fn websocket_connections() { let (etx, erx) = chan::sync::(0); let (itx, irx) = chan::sync::(0); @@ -152,9 +144,9 @@ mod tests { crossbeam::scope(|scope| { for id in 0..10 { scope.spawn(move || { - connect("ws://localhost:3012", |out| { - out.send(format!(r#"{{ "variant": "StartDownload", "fields": [["{}"]] }}"#, id)) - .expect("couldn't write to websocket"); + ws::connect("ws://localhost:3012", |out| { + let msg = format!(r#"{{ "variant": "StartDownload", "fields": [["{}"]] }}"#, id); + out.send(msg).expect("couldn't write to websocket"); move |msg: ws::Message| { let ev: Event = json::decode(&format!("{}", msg)).unwrap(); -- cgit v1.2.1 From fe4b7df778f78342b68af90f24176563e3a04951 Mon Sep 17 00:00:00 2001 From: Shaun Taheri Date: Mon, 24 Oct 2016 14:14:12 +0200 Subject: Fix blocking Websocket gateway listen call --- src/gateway/websocket.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/gateway/websocket.rs') diff --git a/src/gateway/websocket.rs b/src/gateway/websocket.rs index f63a763..8c597b9 100644 --- a/src/gateway/websocket.rs +++ b/src/gateway/websocket.rs @@ -3,6 +3,7 @@ use chan::Sender; use rustc_serialize::json; use std::collections::HashMap; use std::sync::{Arc, Mutex}; +use std::thread; use ws; use ws::{CloseCode, Handler, Handshake, Message, Sender as WsSender}; use ws::util::Token; @@ -20,13 +21,18 @@ pub struct Websocket { impl Gateway for Websocket { fn initialize(&mut self, itx: Sender) -> Result<(), String> { - ws::listen(&self.server.clone() as &str, |out| { - WebsocketHandler { - out: out, - itx: itx.clone(), - clients: self.clients.clone() - } - }).expect("couldn't start websocket listener"); + let clients = self.clients.clone(); + let addr = self.server.clone(); + + thread::spawn(move || { + ws::listen(&addr as &str, |out| { + WebsocketHandler { + out: out, + itx: itx.clone(), + clients: clients.clone() + } + }).expect("couldn't start websocket listener"); + }); Ok(info!("Websocket gateway started at {}.", self.server)) } -- cgit v1.2.1