mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-25 05:03:05 +00:00
vmm_vhost: simplify header reads in Endpoint
Change-Id: Ic287525c91d5890bb5a09fcbe6c872ea427cb677 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5066132 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
parent
e44284f9de
commit
6bfa3f6ce9
1 changed files with 3 additions and 16 deletions
19
third_party/vmm_vhost/src/connection.rs
vendored
19
third_party/vmm_vhost/src/connection.rs
vendored
|
@ -263,17 +263,10 @@ impl<R: Req> Endpoint<R> {
|
|||
/// other file descriptor will be discard silently.
|
||||
pub fn recv_header(&self) -> Result<(VhostUserMsgHeader<R>, Option<Vec<File>>)> {
|
||||
let mut hdr = VhostUserMsgHeader::default();
|
||||
let (bytes, files) = self.0.recv_into_bufs(
|
||||
&mut [IoSliceMut::new(hdr.as_bytes_mut())],
|
||||
true, /* allow_fd */
|
||||
)?;
|
||||
|
||||
if bytes != mem::size_of::<VhostUserMsgHeader<R>>() {
|
||||
return Err(Error::PartialMessage);
|
||||
} else if !hdr.is_valid() {
|
||||
let files = self.recv_into_bufs_all(&mut [hdr.as_bytes_mut()])?;
|
||||
if !hdr.is_valid() {
|
||||
return Err(Error::InvalidMessage);
|
||||
}
|
||||
|
||||
Ok((hdr, files))
|
||||
}
|
||||
|
||||
|
@ -320,13 +313,7 @@ impl<R: Req> Endpoint<R> {
|
|||
pub fn recv_message_with_payload<T: AsBytes + FromBytes + VhostUserMsgValidator>(
|
||||
&self,
|
||||
) -> Result<(VhostUserMsgHeader<R>, T, Vec<u8>, Option<Vec<File>>)> {
|
||||
let mut hdr = VhostUserMsgHeader::default();
|
||||
let mut slices = [hdr.as_bytes_mut()];
|
||||
let files = self.recv_into_bufs_all(&mut slices)?;
|
||||
|
||||
if !hdr.is_valid() {
|
||||
return Err(Error::InvalidMessage);
|
||||
}
|
||||
let (hdr, files) = self.recv_header()?;
|
||||
|
||||
let mut body = T::new_zeroed();
|
||||
let payload_size = hdr.get_size() as usize - mem::size_of::<T>();
|
||||
|
|
Loading…
Reference in a new issue