From: Ian Jackson Date: Mon, 28 Dec 2020 17:52:42 +0000 (+0000) Subject: move MgmtChannel::connect to mgmtchannel.rs X-Git-Tag: otter-0.2.0~114 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=7312174329aa8d7d690cb77a42626728114b34a9;p=otter.git move MgmtChannel::connect to mgmtchannel.rs Signed-off-by: Ian Jackson --- diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 9e0e41e7..3a5f1c76 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -618,9 +618,7 @@ impl ConnForGame { #[throws(E)] fn connect(ma: &MainOpts) -> Conn { - let unix = UnixStream::connect(&ma.socket_path) - .with_context(||ma.socket_path.clone()).context("connect to server")?; - let chan = MgmtChannel::new(unix)?; + let chan = MgmtChannel::connect(&ma.socket_path)?; let mut chan = Conn { chan }; if ma.superuser { chan.cmd(&MC::SetSuperuser(true))?; diff --git a/src/mgmtchannel.rs b/src/mgmtchannel.rs index fd107727..245510fe 100644 --- a/src/mgmtchannel.rs +++ b/src/mgmtchannel.rs @@ -18,6 +18,15 @@ pub struct MgmtChannel { } impl MgmtChannel { + #[throws(AE)] + pub fn connect(socket_path: &str) -> MgmtChannel { + let unix = UnixStream::connect(socket_path) + .with_context(||socket_path.to_owned()) + .context("connect to server")?; + let chan = MgmtChannel::new(unix)?; + chan + } + #[throws(AE)] pub fn new(conn: U) -> MgmtChannel { let read = conn.try_clone().context("dup the command stream")?;