From: Ian Jackson Date: Sat, 1 May 2021 23:22:02 +0000 (+0100) Subject: cmdlistener: Fix writer framing on errors, restructure X-Git-Tag: otter-0.6.0~482 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=0845451d803829914f466a35add892d8b844a3ec;p=otter.git cmdlistener: Fix writer framing on errors, restructure Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 6b0d481d..4df65db1 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -69,7 +69,7 @@ type PCH = PermissionCheckHow; //#[throws(CSE)] fn execute_and_respond(cs: &mut CommandStreamData, cmd: MgmtCommand, mut bulk_upload: ReadFrame, - mut for_response: WriteFrame) + for_response: &mut FrameWriter) -> Result<(), CSE> where R: Read, W: Write { @@ -310,6 +310,7 @@ fn execute_and_respond(cs: &mut CommandStreamData, cmd: MgmtCommand, } }; + let mut for_response = for_response.new_frame()?; rmp_serde::encode::write_named(&mut for_response, &resp).context("respond")?; bulk_download(&mut for_response).context("download")?; for_response.finish().context("flush")?; @@ -1213,8 +1214,7 @@ impl CommandStream<'_> { use MgmtChannelReadError::*; match self.chan.read.read_withbulk::() { Ok((cmd, rbulk)) => { - let wf = self.chan.write.new_frame()?; - execute_and_respond(&mut self.d, cmd, rbulk, wf)?; + execute_and_respond(&mut self.d, cmd, rbulk, &mut self.chan.write)?; }, Err(EOF) => break, Err(IO(e)) => Err(e).context("read command stream")?,