From 0e0fb74bbc27241c35c743a4e7916c6868b5ee3b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 2 May 2021 00:35:58 +0100 Subject: [PATCH] cmdlistener: Provide cmd_withbulk Signed-off-by: Ian Jackson --- src/mgmtchannel.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/mgmtchannel.rs b/src/mgmtchannel.rs index cf54988b..04e7474a 100644 --- a/src/mgmtchannel.rs +++ b/src/mgmtchannel.rs @@ -69,10 +69,16 @@ impl MgmtChannel { } #[throws(AE)] - pub fn cmd(&mut self, cmd: &MgmtCommand) -> MgmtResponse { + pub fn cmd_withbulk(&mut self, cmd: &MgmtCommand, + up: &mut U, down: &mut D) + -> MgmtResponse + where U: Read, D: Write + { use MgmtResponse::*; - self.write.write(&cmd).context("send command")?; - let resp = self.read.read().context("read response")?; + let mut wbulk = self.write.write_withbulk(&cmd).context("send command")?; + io::copy(up,&mut wbulk).context("copy bulk upload")?; + wbulk.finish().context("finish sending command and data")?; + let (resp, mut rbulk)= self.read.read_withbulk().context("read response")?; match &resp { Fine | AccountsList{..} | GamesList{..} | LibraryItems(_) => { }, AlterGame { error: None, .. } => { }, @@ -95,9 +101,16 @@ impl MgmtChannel { ))?; } }; + + io::copy(&mut rbulk, down).context("copy bulk download")?; resp } + #[throws(AE)] + pub fn cmd(&mut self, cmd: &MgmtCommand) -> MgmtResponse { + self.cmd_withbulk(cmd, &mut io::empty(), &mut io::sink())? + } + #[throws(AE)] pub fn list_items(&mut self, pat: &shapelib::ItemSpec) -> Vec { -- 2.30.2