pub struct IoContext(/* private fields */);
Expand description
Newtype for aio_context_t
.
Implementations§
Source§impl IoContext
impl IoContext
Sourcepub fn submit(&self, iocbs: &[&mut IoControlBlock]) -> Result<usize>
pub fn submit(&self, iocbs: &[&mut IoControlBlock]) -> Result<usize>
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);
Sourcepub fn cancel(&self, iocb: &IoControlBlock, result: &mut IoEvent) -> Result<()>
pub fn cancel(&self, iocb: &IoControlBlock, result: &mut IoEvent) -> Result<()>
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.
Sourcepub fn get_events(
&self,
min_nr: c_long,
events: &mut [IoEvent],
timeout: Option<&mut timespec>,
) -> Result<usize>
pub fn get_events( &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 Freeze for IoContext
impl RefUnwindSafe for IoContext
impl Send for IoContext
impl Sync for IoContext
impl Unpin for IoContext
impl UnwindSafe for IoContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more