diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-03-29 13:02:45 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-03-29 13:02:45 +0200 |
| commit | 4a539058f82f23f39cb758ca05226b145a2a2e17 (patch) | |
| tree | 0b2858aae44675c4ae07b459615fac1e7861c0d1 | |
| parent | 075f980a12f3b7e81da93928d475278b67b0cc47 (diff) | |
| parent | d9f6bd04dc79e47acbd4f9ceab03346ac81eaafb (diff) | |
| download | mullvadvpn-4a539058f82f23f39cb758ca05226b145a2a2e17.tar.xz mullvadvpn-4a539058f82f23f39cb758ca05226b145a2a2e17.zip | |
Merge branch 'http-ipc-shortcuts'
| -rw-r--r-- | talpid_ipc/src/http_ipc.rs | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/talpid_ipc/src/http_ipc.rs b/talpid_ipc/src/http_ipc.rs index 15304e87fa..7613f9fa82 100644 --- a/talpid_ipc/src/http_ipc.rs +++ b/talpid_ipc/src/http_ipc.rs @@ -9,11 +9,11 @@ use std::time::Duration; pub struct HttpServerHandle { pub address: IpcServerId, - stop_tx: mpsc::SyncSender<u8>, + stop_tx: mpsc::SyncSender<()>, } impl HttpServerHandle { pub fn stop(&self) { - let _ = self.stop_tx.send(0); + let _ = self.stop_tx.send(()); } } impl Drop for HttpServerHandle { @@ -51,26 +51,21 @@ fn start_http_server(addr: &str) -> Result<tiny_http::Server> { fn start_receive_loop<T, U, F>(mut on_message: F, http_server: tiny_http::Server, - stop_rx: mpsc::Receiver<u8>) + stop_rx: mpsc::Receiver<()>) where T: serde::Deserialize + 'static, U: serde::Serialize, F: FnMut(Result<T>) -> U + Send + 'static { - thread::spawn(move || loop { - if should_stop(&stop_rx) { - debug!("Stopping the server"); - break; + thread::spawn(move || { + while !should_stop(&stop_rx) { + receive(&mut on_message, &http_server); } - - receive(&mut on_message, &http_server); + debug!("Stopping the HTTP IPC server"); }); } -fn should_stop(stop_rx: &mpsc::Receiver<u8>) -> bool { - match stop_rx.try_recv() { - Err(mpsc::TryRecvError::Empty) => false, - _ => true, - } +fn should_stop(stop_rx: &mpsc::Receiver<()>) -> bool { + stop_rx.try_recv() != Err(mpsc::TryRecvError::Empty) } fn receive<T, U, F>(on_message: &mut F, http_server: &tiny_http::Server) |
