From: Ian Jackson Date: Mon, 31 May 2021 20:24:54 +0000 (+0100) Subject: mgmtchannels: Genericise again X-Git-Tag: otter-0.7.0~190 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=4e448eb646d1085d211748f5f29d37acc2b353ca;p=otter.git mgmtchannels: Genericise again Client wants to be Box etc. so it can be ssh pipes. Signed-off-by: Ian Jackson --- diff --git a/apitest/apitest.rs b/apitest/apitest.rs index 2a34fa69..d1db9bad 100644 --- a/apitest/apitest.rs +++ b/apitest/apitest.rs @@ -21,6 +21,8 @@ pub use serde_json::json; pub use structopt::StructOpt; pub use reqwest; +pub type MgmtChannel = ClientMgmtChannel; + pub type JsV = serde_json::Value; pub type MC = MgmtCommand; diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 31c606ee..744dfafa 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -39,7 +39,7 @@ pub struct CommandListener { } struct CommandStream<'d> { - chan: MgmtChannel, + chan: MgmtChannel, d: CommandStreamData<'d>, } @@ -1535,7 +1535,7 @@ impl CommandListener { })().unwrap_or_else(|e| format!("", e)); write!(&mut desc, " user={}", user_desc)?; - let chan = MgmtChannel::new(conn)?; + let chan = MgmtChannel::new_timed(conn)?; let d = CommandStreamData { account: None, desc: &desc, diff --git a/src/bin/otter.rs b/src/bin/otter.rs index c3f2e94d..4368dccd 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -4,6 +4,8 @@ #![allow(unused_imports)] +pub type MgmtChannel = ClientMgmtChannel; + // xxx ssh keys: need a force option to set key for non ssh: account use otter::imports::*; @@ -515,7 +517,7 @@ fn main() { } struct Conn { - chan: MgmtChannel, + chan: ClientMgmtChannel, } deref_to_field_mut!{Conn, MgmtChannel, chan} diff --git a/src/mgmtchannel.rs b/src/mgmtchannel.rs index 473fdde1..0d937044 100644 --- a/src/mgmtchannel.rs +++ b/src/mgmtchannel.rs @@ -34,32 +34,32 @@ impl From for MgmtChannelWriteError { } } -pub struct MgmtChannel { - pub read: FrameReader, - pub write: FrameWriter, +pub struct MgmtChannel { + pub read: FrameReader, + pub write: FrameWriter, } -impl Debug for MgmtChannel{ +impl Debug for MgmtChannel where R: Read, W: Write { #[throws(fmt::Error)] fn fmt(&self, f: &mut fmt::Formatter) { f.write_str("MgmtChannel{...}")? } } -impl MgmtChannel { - pub const PROGRESS: ProgressUpdateMode = PUM::Duplex; +pub type ClientMgmtChannel = MgmtChannel; +impl MgmtChannel { #[throws(AE)] - pub fn connect(socket_path: &str) -> MgmtChannel { + pub fn connect(socket_path: &str) -> Self { let unix = UnixStream::connect(socket_path) .with_context(||socket_path.to_owned()) .context("connect to server")?; - let chan = MgmtChannel::new(unix)?; + let chan = MgmtChannel::new_timed(unix)?; chan } #[throws(AE)] - pub fn new(conn: U) -> MgmtChannel + pub fn new_timed(conn: U) -> Self where U: IoTryClone + Read + Write + IntoRawFd + Send + 'static, { let read = conn.try_clone().context("dup the command stream")?; @@ -69,6 +69,16 @@ impl MgmtChannel { let write = FrameWriter::new(write); MgmtChannel { read, write } } +} + +impl MgmtChannel where R: Read, W: Write + Send { + pub fn read_inner_mut(&mut self) -> &mut R { + self.read.inner_mut() + } +} + +impl ClientMgmtChannel { + pub const PROGRESS: ProgressUpdateMode = PUM::Duplex; #[throws(AE)] pub fn cmd_withbulk(&mut self, cmd: &MgmtCommand, @@ -146,10 +156,6 @@ impl MgmtChannel { &mut termprogress::Null)? } - pub fn read_inner_mut(&mut self) -> &mut TimedFdReader { - self.read.inner_mut() - } - pub fn for_game(self, game: InstanceName, how: MgmtGameUpdateMode) -> MgmtChannelForGame { MgmtChannelForGame { @@ -170,11 +176,11 @@ impl IoTryClone for UnixStream { #[derive(Debug)] pub struct MgmtChannelForGame { - pub chan: MgmtChannel, + pub chan: ClientMgmtChannel, pub game: InstanceName, pub how: MgmtGameUpdateMode, } -deref_to_field_mut!{MgmtChannelForGame, MgmtChannel, chan} +deref_to_field_mut!{MgmtChannelForGame, ClientMgmtChannel, chan} impl MgmtChannelForGame { #[throws(AE)] diff --git a/src/prelude.rs b/src/prelude.rs index 3a572af3..ef162842 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -144,8 +144,8 @@ pub use crate::gamestate::*; pub use crate::global::*; pub use crate::hidden::*; pub use crate::keydata::*; -pub use crate::mgmtchannel::*; pub use crate::nwtemplates; +pub use crate::mgmtchannel::*; pub use crate::occultilks::*; pub use crate::organise; pub use crate::packetframe::{FrameReader, FrameWriter, ReadFrame, WriteFrame}; diff --git a/src/timedfd.rs b/src/timedfd.rs index b592d722..641b1fba 100644 --- a/src/timedfd.rs +++ b/src/timedfd.rs @@ -165,3 +165,4 @@ impl Drop for Fd { if fd >= 2 { let _ = nix::unistd::close(fd); } } } +