diff options
| author | Emīls <emils@mullvad.net> | 2020-03-03 12:05:13 +0000 |
|---|---|---|
| committer | Emīls <emils@mullvad.net> | 2020-03-13 19:20:32 +0000 |
| commit | b217d3a7e224ce309ac6c4092e8fec6b4dbc3c51 (patch) | |
| tree | a43dfa86476601a4a6c093845cf4a7ce54cf8414 /talpid-core/src | |
| parent | d5184944bd375db027eef599e3eeadea479c00fd (diff) | |
| download | mullvadvpn-b217d3a7e224ce309ac6c4092e8fec6b4dbc3c51.tar.xz mullvadvpn-b217d3a7e224ce309ac6c4092e8fec6b4dbc3c51.zip | |
Add a shutdown channel for the tunnel state machine
Diffstat (limited to 'talpid-core/src')
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/mod.rs | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/talpid-core/src/tunnel_state_machine/mod.rs b/talpid-core/src/tunnel_state_machine/mod.rs index 773a14e8da..5379a76740 100644 --- a/talpid-core/src/tunnel_state_machine/mod.rs +++ b/talpid-core/src/tunnel_state_machine/mod.rs @@ -21,7 +21,10 @@ use crate::{ offline, tunnel::tun_provider::TunProvider, }; -use futures::{sync::mpsc, Async, Future, Poll, Stream}; +use futures::{ + sync::{mpsc, oneshot}, + Async, Future, Poll, Stream, +}; use std::{ io, path::{Path, PathBuf}, @@ -70,6 +73,7 @@ pub fn spawn( resource_dir: PathBuf, cache_dir: impl AsRef<Path> + Send + 'static, state_change_listener: impl Sender<TunnelStateTransition> + Send + 'static, + shutdown_tx: oneshot::Sender<()>, #[cfg(target_os = "android")] android_context: AndroidContext, ) -> Result<Arc<mpsc::UnboundedSender<TunnelCommand>>, Error> { let (command_tx, command_rx) = mpsc::unbounded(); @@ -102,6 +106,7 @@ pub fn spawn( cache_dir, command_rx, state_change_listener, + shutdown_tx, ) { Ok((mut reactor, event_loop)) => { startup_result_tx.send(Ok(())).expect( @@ -141,6 +146,7 @@ fn create_event_loop( cache_dir: impl AsRef<Path>, commands: mpsc::UnboundedReceiver<TunnelCommand>, state_change_listener: impl Sender<TunnelStateTransition>, + shutdown_tx: oneshot::Sender<()>, ) -> Result<(Core, impl Future<Item = (), Error = Error>), Error> { let reactor = Core::new().map_err(Error::ReactorError)?; let state_machine = TunnelStateMachine::new( @@ -155,11 +161,18 @@ fn create_event_loop( commands, )?; - let future = state_machine.for_each(move |state_change_event| { - state_change_listener - .send(state_change_event) - .map_err(|_| Error::SendStateChange) - }); + let future = state_machine + .for_each(move |state_change_event| { + state_change_listener + .send(state_change_event) + .map_err(|_| Error::SendStateChange) + }) + .then(move |_| { + if shutdown_tx.send(()).is_err() { + log::error!("Can't send shutdown completion to daemon"); + } + Ok(()) + }); Ok((reactor, future)) } |
