(
&mut self,
offset: libc::off_t,
iovecs: &[libc::iovec],
user_data: u64,
eventfd: &EventFd,
completion_list: &mut VecDeque<(u64, i32)>,
)
| 454 | |
| 455 | pub trait AsyncAdaptor { |
| 456 | fn read_vectored_sync( |
| 457 | &mut self, |
| 458 | offset: libc::off_t, |
| 459 | iovecs: &[libc::iovec], |
| 460 | user_data: u64, |
| 461 | eventfd: &EventFd, |
| 462 | completion_list: &mut VecDeque<(u64, i32)>, |
| 463 | ) -> AsyncIoResult<()> |
| 464 | where |
| 465 | Self: Read + Seek, |
| 466 | { |
| 467 | // Convert libc::iovec into IoSliceMut |
| 468 | let mut slices: SmallVec<[IoSliceMut; DEFAULT_DESCRIPTOR_VEC_SIZE]> = |
| 469 | SmallVec::with_capacity(iovecs.len()); |
| 470 | for iovec in iovecs.iter() { |
| 471 | // SAFETY: on Linux IoSliceMut wraps around libc::iovec |
| 472 | slices.push(IoSliceMut::new(unsafe { |
| 473 | std::mem::transmute::<libc::iovec, &mut [u8]>(*iovec) |
| 474 | })); |
| 475 | } |
| 476 | |
| 477 | let result = { |
| 478 | // Move the cursor to the right offset |
| 479 | self.seek(SeekFrom::Start(offset as u64)) |
| 480 | .map_err(AsyncIoError::ReadVectored)?; |
| 481 | |
| 482 | let mut r = 0; |
| 483 | for b in slices.iter_mut() { |
| 484 | r += self.read(b).map_err(AsyncIoError::ReadVectored)?; |
| 485 | } |
| 486 | r |
| 487 | }; |
| 488 | |
| 489 | completion_list.push_back((user_data, result as i32)); |
| 490 | eventfd.write(1).unwrap(); |
| 491 | |
| 492 | Ok(()) |
| 493 | } |
| 494 | |
| 495 | fn write_vectored_sync( |
| 496 | &mut self, |
no test coverage detected