[−][src]Struct vmm_sys_util::aio::IoContext
Newtype for aio_context_t
.
Implementations
impl IoContext
[src]
pub fn new(nr_events: c_uint) -> Result<Self>
[src]
Create a new aio context instance.
Refer to Linux io_setup
.
Arguments
nr_events
: maximum number of concurrently processing IO operations.
pub fn submit(&self, iocbs: &[&mut IoControlBlock]) -> Result<usize>
[src]
Submit asynchronous I/O blocks for processing.
Refer to Linux io_submit
.
Arguments
iocbs
: array of AIO control blocks, which will be submitted to the context.
Examples
extern crate vmm_sys_util; use vmm_sys_util::aio::*; let file = File::open("/dev/zero").unwrap(); let ctx = IoContext::new(128).unwrap(); let mut buf: [u8; 4096] = unsafe { std::mem::uninitialized() }; let iocbs = [ &mut IoControlBlock { aio_fildes: file.as_raw_fd() as u32, aio_lio_opcode: IOCB_CMD_PREAD as u16, aio_buf: buf.as_mut_ptr() as u64, aio_nbytes: buf.len() as u64, ..Default::default() }, ]; assert_eq!(ctx.submit(&iocbs[..]).unwrap(), 1);
pub fn cancel(&self, iocb: &IoControlBlock, result: &mut IoEvent) -> Result<()>
[src]
Cancel an outstanding asynchronous I/O operation.
Refer to Linux io_cancel
.
Note: according to current Linux kernel implementation(v4.19), libc::SYS_io_cancel always
return failure, thus rendering it useless.
Arguments
iocb
: The iocb for the operation to be canceled.result
: If the operation is successfully canceled, the event will be copied into the memory pointed to by result without being placed into the completion queue.
pub fn get_events(
&self,
min_nr: c_long,
events: &mut [IoEvent],
timeout: Option<&mut timespec>
) -> Result<usize>
[src]
&self,
min_nr: c_long,
events: &mut [IoEvent],
timeout: Option<&mut timespec>
) -> Result<usize>
Read asynchronous I/O events from the completion queue.
Refer to Linux io_getevents
.
Arguments
min_nr
: read at least min_nr events.events
: array to receive the io operation results.timeout
: optional amount of time to wait for events.
Examples
extern crate vmm_sys_util; use vmm_sys_util::aio::*; let file = File::open("/dev/zero").unwrap(); let ctx = IoContext::new(128).unwrap(); let mut buf: [u8; 4096] = unsafe { std::mem::uninitialized() }; let iocbs = [ &mut IoControlBlock { aio_fildes: file.as_raw_fd() as u32, aio_lio_opcode: IOCB_CMD_PREAD as u16, aio_buf: buf.as_mut_ptr() as u64, aio_nbytes: buf.len() as u64, ..Default::default() }, &mut IoControlBlock { aio_fildes: file.as_raw_fd() as u32, aio_lio_opcode: IOCB_CMD_PREAD as u16, aio_buf: buf.as_mut_ptr() as u64, aio_nbytes: buf.len() as u64, ..Default::default() }, ]; let mut rc = ctx.submit(&iocbs[..]).unwrap(); let mut events = [unsafe { std::mem::uninitialized::<IoEvent>() }]; rc = ctx.get_events(1, &mut events, None).unwrap(); assert_eq!(rc, 1); assert!(events[0].res > 0); rc = ctx.get_events(1, &mut events, None).unwrap(); assert_eq!(rc, 1); assert!(events[0].res > 0);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for IoContext
impl Send for IoContext
impl Sync for IoContext
impl Unpin for IoContext
impl UnwindSafe for IoContext
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,