From cb8d06cd450d8b9fdfc1023063550569ae7e2f12 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 31 May 2021 21:37:44 +0100 Subject: [PATCH] mgmtchannels: Change type of ClientMgmtChannel Signed-off-by: Ian Jackson --- src/mgmtchannel.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/mgmtchannel.rs b/src/mgmtchannel.rs index 6a8c8634..772f0990 100644 --- a/src/mgmtchannel.rs +++ b/src/mgmtchannel.rs @@ -46,18 +46,30 @@ impl Debug for MgmtChannel where R: Read, W: Write { } } -pub type ClientMgmtChannel = MgmtChannel; +pub type ClientMgmtChannel = MgmtChannel< + Box, + Box, + >; -impl MgmtChannel { +impl ClientMgmtChannel { #[throws(AE)] 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_timed(unix)?; - chan + let read = unix.try_clone().context("dup the client connection")?; + let write = unix; + MgmtChannel::new_boxed(read, write) + } + + pub fn new_boxed(read: R, write: W) -> Self + where R: Read + 'static, + W: Write + Send + 'static { + MgmtChannel::new_raw(Box::new(read), Box::new(write)) } +} +impl MgmtChannel { #[throws(AE)] pub fn new_timed(conn: U) -> Self where U: IoTryClone + Read + Write + IntoRawFd + Send + 'static, @@ -65,12 +77,12 @@ impl MgmtChannel { let read = conn.try_clone().context("dup the command stream")?; let read = TimedFdReader::new(read).context("set up timed reader")?; let write = TimedFdWriter::new(conn).context("set up timed writerr")?; - MgmtChannel::new(read, write) + MgmtChannel::new_raw(read, write) } } impl MgmtChannel where R: Read, W: Write + Send { - pub fn new(read: R, write: W) -> Self { + pub fn new_raw(read: R, write: W) -> Self { let read = FrameReader::new(read); let write = FrameWriter::new(write); MgmtChannel { read, write } -- 2.30.2