chiark / gitweb /
cmdlistener: Provide cmd_withbulk
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 1 May 2021 23:35:58 +0000 (00:35 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 May 2021 00:02:18 +0000 (01:02 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/mgmtchannel.rs

index cf54988b75c701cdba18a2996e30ece8ab055f96..04e7474a3582cd76c3dd5c8035f9437acb10017a 100644 (file)
@@ -69,10 +69,16 @@ impl MgmtChannel {
   }
 
   #[throws(AE)]
-  pub fn cmd(&mut self, cmd: &MgmtCommand) -> MgmtResponse {
+  pub fn cmd_withbulk<U,D>(&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<shapelib::ItemEnquiryData> {