Trait nix::sys::aio::Aio

source ·
pub trait Aio {
    type Output;

    // Required methods
    fn aio_return(self: Pin<&mut Self>) -> Result<Self::Output>;
    fn cancel(self: Pin<&mut Self>) -> Result<AioCancelStat>;
    fn error(self: Pin<&mut Self>) -> Result<()>;
    fn fd(&self) -> BorrowedFd<'_>;
    fn in_progress(&self) -> bool;
    fn priority(&self) -> i32;
    fn set_sigev_notify(&mut self, sev: SigevNotify<'_>);
    fn sigevent(&self) -> SigEvent;
    fn submit(self: Pin<&mut Self>) -> Result<()>;
}
Expand description

Methods common to all AIO operations

Required Associated Types§

source

type Output

The return type of Aio::aio_return.

Required Methods§

source

fn aio_return(self: Pin<&mut Self>) -> Result<Self::Output>

Retrieve return status of an asynchronous operation.

Should only be called once for each operation, after Aio::error indicates that it has completed. The result is the same as for the synchronous read(2), write(2), of fsync(2) functions.

§References

aio_return

source

fn cancel(self: Pin<&mut Self>) -> Result<AioCancelStat>

Cancels an outstanding AIO request.

The operating system is not required to implement cancellation for all file and device types. Even if it does, there is no guarantee that the operation has not already completed. So the caller must check the result and handle operations that were not canceled or that have already completed.

§Examples

Cancel an outstanding aio operation. Note that we must still call aio_return to free resources, even though we don’t care about the result.

let wbuf = b"CDEF";
let mut f = tempfile().unwrap();
let mut aiocb = Box::pin(AioWrite::new(f.as_fd(),
    2,   //offset
    &wbuf[..],
    0,   //priority
    SigevNotify::SigevNone));
aiocb.as_mut().submit().unwrap();
let cs = aiocb.as_mut().cancel().unwrap();
if cs == AioCancelStat::AioNotCanceled {
    while (aiocb.as_mut().error() == Err(Errno::EINPROGRESS)) {
        thread::sleep(time::Duration::from_millis(10));
    }
}
// Must call `aio_return`, but ignore the result
let _ = aiocb.as_mut().aio_return();
§References

aio_cancel

source

fn error(self: Pin<&mut Self>) -> Result<()>

Retrieve error status of an asynchronous operation.

If the request has not yet completed, returns EINPROGRESS. Otherwise, returns Ok or any other error.

§Examples

Issue an aio operation and use error to poll for completion. Polling is an alternative to aio_suspend, used by most of the other examples.

const WBUF: &[u8] = b"abcdef123456";
let mut f = tempfile().unwrap();
let mut aiocb = Box::pin(AioWrite::new(f.as_fd(),
    2,   //offset
    WBUF,
    0,   //priority
    SigevNotify::SigevNone));
aiocb.as_mut().submit().unwrap();
while (aiocb.as_mut().error() == Err(Errno::EINPROGRESS)) {
    thread::sleep(time::Duration::from_millis(10));
}
assert_eq!(aiocb.as_mut().aio_return().unwrap(), WBUF.len());
§References

aio_error

source

fn fd(&self) -> BorrowedFd<'_>

Returns the underlying file descriptor associated with the operation.

source

fn in_progress(&self) -> bool

Does this operation currently have any in-kernel state?

Dropping an operation that does have in-kernel state constitutes a resource leak.

§Examples
let f = tempfile().unwrap();
let mut aiof = Box::pin(AioFsync::new(f.as_fd(), AioFsyncMode::O_SYNC,
    0, SigevNone));
assert!(!aiof.as_mut().in_progress());
aiof.as_mut().submit().expect("aio_fsync failed early");
assert!(aiof.as_mut().in_progress());
while (aiof.as_mut().error() == Err(Errno::EINPROGRESS)) {
    thread::sleep(time::Duration::from_millis(10));
}
aiof.as_mut().aio_return().expect("aio_fsync failed late");
assert!(!aiof.as_mut().in_progress());
source

fn priority(&self) -> i32

Returns the priority of the AioCb

source

fn set_sigev_notify(&mut self, sev: SigevNotify<'_>)

Update the notification settings for an existing AIO operation that has not yet been submitted.

source

fn sigevent(&self) -> SigEvent

Returns the SigEvent that will be used for notification.

source

fn submit(self: Pin<&mut Self>) -> Result<()>

Actually start the I/O operation.

After calling this method and until Aio::aio_return returns Ok, the structure may not be moved in memory.

Implementors§

source§

impl<'a> Aio for AioFsync<'a>

source§

impl<'a> Aio for AioRead<'a>

source§

impl<'a> Aio for AioWrite<'a>