From 9d174f4152c509a7b8d2c6ac18d26d2b3401265c Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 25 Jan 2018 14:24:41 +0100 Subject: net: Attach Context to Descriptor. - Now that the Context is Send + Clone, we can attach a clone to the Descriptor and pass it to the server thread. --- net/src/ipc.rs | 19 +++++++++++-------- store/src/backend/mod.rs | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/net/src/ipc.rs b/net/src/ipc.rs index a4e84d81..31cd16d6 100644 --- a/net/src/ipc.rs +++ b/net/src/ipc.rs @@ -82,9 +82,8 @@ pub type HandlerFactory = fn(descriptor: Descriptor, /// A descriptor is used to connect to a service. #[derive(Clone)] pub struct Descriptor { - ipc_policy: core::IPCPolicy, - pub home: PathBuf, - pub rendezvous: PathBuf, + ctx: core::Context, + rendezvous: PathBuf, executable: PathBuf, factory: HandlerFactory, } @@ -98,14 +97,18 @@ impl Descriptor { executable: PathBuf, factory: HandlerFactory) -> Self { Descriptor { - home: ctx.home().into(), - ipc_policy: *ctx.ipc_policy(), + ctx: ctx.clone(), rendezvous: rendezvous, executable: executable, factory: factory, } } + /// Returns the context. + pub fn context(&self) -> &core::Context { + &self.ctx + } + /// Connect to a descriptor, starting the server if necessary. pub fn connect(&self, handle: &tokio_core::reactor::Handle) -> io::Result> { let do_connect = @@ -159,7 +162,7 @@ impl Descriptor { let cookie = Cookie::new()?; for external in [true, false].iter() { // Implement the IPC pocicy. - if self.ipc_policy == core::IPCPolicy::Internal && *external { + if *self.ctx.ipc_policy() == core::IPCPolicy::Internal && *external { // Do not try to fork. continue; } @@ -167,7 +170,7 @@ impl Descriptor { let addr = match self.start(*external) { Ok(a) => a, Err(e) => if *external { - if self.ipc_policy == core::IPCPolicy::External { + if *self.ctx.ipc_policy() == core::IPCPolicy::External { // Fail! return Err(e); } @@ -236,7 +239,7 @@ impl Descriptor { Command::new(&self.executable.clone().into_os_string()) .arg("--home") - .arg(self.home.to_string_lossy().into_owned()) + .arg(self.ctx.home().to_string_lossy().into_owned()) // l will be closed here if the exec fails. .stdin(unsafe { Stdio::from_raw_fd(fd) }) .spawn()?; diff --git a/store/src/backend/mod.rs b/store/src/backend/mod.rs index 10afe15a..d4f8ca3f 100644 --- a/store/src/backend/mod.rs +++ b/store/src/backend/mod.rs @@ -94,7 +94,7 @@ struct NodeServer { impl NodeServer { fn new(descriptor: ipc::Descriptor, handle: Handle) -> Result { - let mut db_path = descriptor.home.clone(); + let mut db_path = descriptor.context().home().to_path_buf(); db_path.push("keystore.sqlite"); let c = Connection::open(db_path)?; -- cgit v1.2.3