// Helper that polls an AioCb for completion or error
macro_rules! poll_aio {
($aiocb: expr) => { loop { let err = $aiocb.as_mut().error(); if err != Err(Errno::EINPROGRESS) { break err;
};
thread::sleep(time::Duration::from_millis(10));
}
};
}
mod aio_fsync { usesuper::*;
#[test] fn test_accessors() { let f = tempfile().unwrap(); let aiocb = AioFsync::new(
f.as_fd(),
AioFsyncMode::O_SYNC, 42,
SigevNotify::SigevSignal {
signal: Signal::SIGUSR2,
si_value: 99,
},
);
assert_eq!(f.as_raw_fd(), aiocb.fd().as_raw_fd());
assert_eq!(AioFsyncMode::O_SYNC, aiocb.mode());
assert_eq!(42, aiocb.priority()); let sev = aiocb.sigevent().sigevent();
assert_eq!(Signal::SIGUSR2 as i32, sev.sigev_signo);
assert_eq!(99, sev.sigev_value.sival_ptr as i64);
}
/// `AioFsync::submit` should not modify the `AioCb` object if /// `libc::aio_fsync` returns an error // Skip on Linux, because Linux's AIO implementation can't detect errors // synchronously #[test] #[cfg_attr(any(target_os = "android", target_os = "linux"), ignore)] fn error() { use std::mem;
const INITIAL: &[u8] = b"abcdef123456"; // Create an invalid AioFsyncMode let mode = unsafe { mem::transmute::<i32, AioFsyncMode>(666) }; letmut f = tempfile().unwrap();
f.write_all(INITIAL).unwrap(); letmut aiof = Box::pin(AioFsync::new(f.as_fd(), mode, 0, SigevNotify::SigevNone)); let err = aiof.as_mut().submit();
err.expect_err("assertion failed");
}
#[test] fn test_accessors() { let f = tempfile().unwrap(); let wbuf = vec![0; 4]; let aiocb = AioWrite::new(
f.as_fd(), 2, //offset
&wbuf, 42, //priority
SigevNotify::SigevSignal {
signal: Signal::SIGUSR2,
si_value: 99,
},
);
assert_eq!(f.as_raw_fd(), aiocb.fd().as_raw_fd());
assert_eq!(4, aiocb.nbytes());
assert_eq!(2, aiocb.offset());
assert_eq!(42, aiocb.priority()); let sev = aiocb.sigevent().sigevent();
assert_eq!(Signal::SIGUSR2 as i32, sev.sigev_signo);
assert_eq!(99, sev.sigev_value.sival_ptr as i64);
}
// Tests AioWrite.cancel. We aren't trying to test the OS's implementation, // only our bindings. So it's sufficient to check that cancel // returned any AioCancelStat value. #[test] #[cfg_attr(target_env = "musl", ignore)] fn cancel() { let wbuf: &[u8] = b"CDEF";
let f = tempfile().unwrap(); letmut aiow = Box::pin(AioWrite::new(
f.as_fd(), 0,
wbuf, 0,
SigevNotify::SigevNone,
));
aiow.as_mut().submit().unwrap(); let err = aiow.as_mut().error();
assert!(err == Ok(()) || err == Err(Errno::EINPROGRESS));
aiow.as_mut().cancel().unwrap();
// Wait for aiow to complete, but don't care whether it succeeded let _ = poll_aio!(&mut aiow); let _ = aiow.as_mut().aio_return();
}
// Test a simple aio operation with no completion notification. We must // poll for completion. #[test] #[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)] fn ok() { const INITIAL: &[u8] = b"abcdef123456"; let wbuf = "CDEF".to_string().into_bytes(); letmut rbuf = Vec::new(); const EXPECT: &[u8] = b"abCDEF123456";
let err = poll_aio!(&mut aiow);
assert_eq!(err, Ok(()));
assert_eq!(aiow.as_mut().aio_return().unwrap(), wbuf.len());
}
f.rewind().unwrap(); let len = f.read_to_end(&mut rbuf).unwrap();
assert_eq!(len, EXPECT.len());
assert_eq!(rbuf, EXPECT);
}
/// `AioWrite::write` should not modify the `AioCb` object if /// `libc::aio_write` returns an error. // Skip on Linux, because Linux's AIO implementation can't detect errors // synchronously #[test] #[cfg_attr(any(target_os = "android", target_os = "linux"), ignore)] fn error() { // Not I/O safe! Deliberately create an invalid fd. let fd = unsafe { BorrowedFd::borrow_raw(666) }; let wbuf = "CDEF".to_string().into_bytes(); letmut aiow = Box::pin(AioWrite::new(
fd, 0, //offset
&wbuf, 0, //priority
SigevNotify::SigevNone,
));
aiow.as_mut().submit().expect_err("assertion failed"); // Dropping the AioWrite at this point should not panic
}
}
#[cfg(target_os = "freebsd")] #[cfg(fbsd14)] mod aio_writev { use std::io::IoSlice;
usesuper::*;
#[test] fn test_accessors() { let f = tempfile().unwrap(); let wbuf0 = vec![0; 4]; let wbuf1 = vec![0; 8]; let wbufs = [IoSlice::new(&wbuf0), IoSlice::new(&wbuf1)]; let aiocb = AioWritev::new(
f.as_fd(), 2, //offset
&wbufs, 42, //priority
SigevNotify::SigevSignal {
signal: Signal::SIGUSR2,
si_value: 99,
},
);
assert_eq!(f.as_raw_fd(), aiocb.fd().as_raw_fd());
assert_eq!(2, aiocb.iovlen());
assert_eq!(2, aiocb.offset());
assert_eq!(42, aiocb.priority()); let sev = aiocb.sigevent().sigevent();
assert_eq!(Signal::SIGUSR2 as i32, sev.sigev_signo);
assert_eq!(99, sev.sigev_value.sival_ptr as i64);
}
// Test a simple aio operation with no completion notification. We must // poll for completion. #[test] #[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)] fn ok() { const INITIAL: &[u8] = b"abcdef123456"; let wbuf0 = b"BC"; let wbuf1 = b"DEF"; let wbufs = [IoSlice::new(wbuf0), IoSlice::new(wbuf1)]; let wlen = wbuf0.len() + wbuf1.len(); letmut rbuf = Vec::new(); const EXPECT: &[u8] = b"aBCDEF123456";
/// aio_suspend relies on casting Rust Aio* struct pointers to libc::aiocb /// pointers. This test ensures that such casts are valid. #[test] fn casting() { let sev = SigevNotify::SigevNone; // Only safe because we'll never await the futures let fd = unsafe { BorrowedFd::borrow_raw(666) }; let aiof = AioFsync::new(fd, AioFsyncMode::O_SYNC, 0, sev);
assert_eq!(
aiof.as_ref() as *const libc::aiocb,
&aiof as *const AioFsync as *const libc::aiocb
);
letmut rbuf = []; let aior = AioRead::new(fd, 0, &mut rbuf, 0, sev);
assert_eq!(
aior.as_ref() as *const libc::aiocb,
&aior as *const AioRead as *const libc::aiocb
);
let wbuf = []; let aiow = AioWrite::new(fd, 0, &wbuf, 0, sev);
assert_eq!(
aiow.as_ref() as *const libc::aiocb,
&aiow as *const AioWrite as *const libc::aiocb
);
}
#[cfg(target_os = "freebsd")] #[test] fn casting_vectored() { use std::io::{IoSlice, IoSliceMut};
let sev = SigevNotify::SigevNone;
letmut rbuf = []; letmut rbufs = [IoSliceMut::new(&mut rbuf)]; // Only safe because we'll never await the futures let fd = unsafe { BorrowedFd::borrow_raw(666) }; let aiorv = AioReadv::new(fd, 0, &mut rbufs[..], 0, sev);
assert_eq!(
aiorv.as_ref() as *const libc::aiocb,
&aiorv as *const AioReadv as *const libc::aiocb
);
let wbuf = []; let wbufs = [IoSlice::new(&wbuf)]; let aiowv = AioWritev::new(fd, 0, &wbufs, 0, sev);
assert_eq!(
aiowv.as_ref() as *const libc::aiocb,
&aiowv as *const AioWritev as *const libc::aiocb
);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.22 Sekunden
(vorverarbeitet am 2026-06-18)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.