summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-01-28 22:16:10 +0100
committerLinus Färnstrand <linus@mullvad.net>2017-01-30 10:25:52 +0100
commitd0533182dfb1352b0f6cb9494da3283512c74584 (patch)
treeceb7a4de7544f5b0eb5942c59b9ddc05fdd71cdf
parentc97361153b0a78c3f60baeca480f60a218eea05d (diff)
downloadmullvadvpn-d0533182dfb1352b0f6cb9494da3283512c74584.tar.xz
mullvadvpn-d0533182dfb1352b0f6cb9494da3283512c74584.zip
Make child associated type in ChildSpawner
-rw-r--r--src/process/mod.rs4
-rw-r--r--src/process/monitor.rs21
2 files changed, 16 insertions, 9 deletions
diff --git a/src/process/mod.rs b/src/process/mod.rs
index fae68616c8..a82893d64a 100644
--- a/src/process/mod.rs
+++ b/src/process/mod.rs
@@ -138,7 +138,9 @@ impl MonitoredChild for ClonableChild {
}
}
-impl ChildSpawner<ClonableChild> for OpenVpnCommand {
+impl ChildSpawner for OpenVpnCommand {
+ type Child = ClonableChild;
+
fn spawn(&mut self) -> io::Result<ClonableChild> {
OpenVpnCommand::spawn(self).map(|child| child.into_clonable())
}
diff --git a/src/process/monitor.rs b/src/process/monitor.rs
index cf0473223f..c16e9a15a7 100644
--- a/src/process/monitor.rs
+++ b/src/process/monitor.rs
@@ -22,9 +22,12 @@ pub trait MonitoredChild: Clone + Send + 'static {
}
/// Trait for objects that can spawn any type of child process object implementing `MonitoredChild`.
-pub trait ChildSpawner<C: MonitoredChild>: Send + 'static {
+pub trait ChildSpawner: Send + 'static {
+ /// The type of child being spawned.
+ type Child: MonitoredChild;
+
/// Spawns the child process, returning a handle to it on success.
- fn spawn(&mut self) -> io::Result<C>;
+ fn spawn(&mut self) -> io::Result<Self::Child>;
}
@@ -83,12 +86,12 @@ struct RunningState<C: MonitoredChild> {
/// A child process monitor. Takes care of starting and monitoring a child process and runs the
/// listener on child exit.
-pub struct ChildMonitor<C: MonitoredChild, B: ChildSpawner<C>> {
+pub struct ChildMonitor<B: ChildSpawner> {
process_builder: B,
- state: Arc<Mutex<State<C>>>,
+ state: Arc<Mutex<State<B::Child>>>,
}
-impl<C: MonitoredChild, B: ChildSpawner<C>> ChildMonitor<C, B> {
+impl<B: ChildSpawner> ChildMonitor<B> {
/// Creates a new `ChildMonitor` that spawns processes with the given `builder`. The new
/// `ChildMonitor` will be in the stopped state and not start any process until you call
/// `start()`.
@@ -121,7 +124,7 @@ impl<C: MonitoredChild, B: ChildSpawner<C>> ChildMonitor<C, B> {
}
}
- fn spawn_monitor<L>(&self, child: C, mut listener: L) -> thread::JoinHandle<()>
+ fn spawn_monitor<L>(&self, child: B::Child, mut listener: L) -> thread::JoinHandle<()>
where L: FnMut(bool) + Send + 'static
{
let state_mutex = self.state.clone();
@@ -147,7 +150,7 @@ impl<C: MonitoredChild, B: ChildSpawner<C>> ChildMonitor<C, B> {
}
}
-impl<C: MonitoredChild, B: ChildSpawner<C>> Drop for ChildMonitor<C, B> {
+impl<B: ChildSpawner> Drop for ChildMonitor<B> {
fn drop(&mut self) {
let thread_handle = {
let mut state_lock = self.state.lock().unwrap();
@@ -229,7 +232,9 @@ mod child_monitor {
}
}
- impl ChildSpawner<MockChild> for MockChildSpawner {
+ impl ChildSpawner for MockChildSpawner {
+ type Child = MockChild;
+
fn spawn(&mut self) -> io::Result<MockChild> {
self.spawn_result
.clone()