diff --git a/vm-migration/src/protocol.rs b/vm-migration/src/protocol.rs index ad453b178..4789bdf74 100644 --- a/vm-migration/src/protocol.rs +++ b/vm-migration/src/protocol.rs @@ -190,6 +190,22 @@ impl Response { Ok(response) } + pub fn ok_or_abandon( + self, + fd: &mut T, + error: MigratableError, + ) -> Result + where + T: Read + Write, + { + if self.status != Status::Ok { + Request::abandon().write_to(fd)?; + Response::read_from(fd)?; + return Err(error); + } + Ok(self) + } + pub fn write_to(&self, fd: &mut dyn Write) -> Result<(), MigratableError> { fd.write_all(Self::as_slice(self)) .map_err(MigratableError::MigrateSocket)