Struct nix::sys::aio::AioCb [] [src]

pub struct AioCb<'a> { /* fields omitted */ }

AIO Control Block.

The basic structure used by all aio functions. Each AioCb represents one I/O request.

Methods

impl<'a> AioCb<'a>
[src]

[src]

Remove the inner Buffer and return it

It is an error to call this method while the AioCb is still in progress.

[src]

Returns the underlying file descriptor associated with the AioCb

[src]

Constructs a new AioCb with no associated buffer.

The resulting AioCb structure is suitable for use with AioCb::fsync.

Parameters

  • fd: File descriptor. Required for all aio functions.
  • prio: If POSIX Prioritized IO is supported, then the operation will be prioritized at the process's priority level minus prio.
  • sigev_notify: Determines how you will be notified of event completion.

Examples

Create an AioCb from a raw file descriptor and use it for an fsync operation.

let f = tempfile().unwrap();
let mut aiocb = AioCb::from_fd( f.as_raw_fd(), 0, SigevNone);
aiocb.fsync(AioFsyncMode::O_SYNC).expect("aio_fsync failed early");
while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) {
    thread::sleep(time::Duration::from_millis(10));
}
aiocb.aio_return().expect("aio_fsync failed late");

[src]

Constructs a new AioCb from a mutable slice.

The resulting AioCb will be suitable for both read and write operations, but only if the borrow checker can guarantee that the slice will outlive the AioCb. That will usually be the case if the AioCb is stack-allocated. If the borrow checker gives you trouble, try using from_bytes_mut instead.

Parameters

  • fd: File descriptor. Required for all aio functions.
  • offs: File offset
  • buf: A memory buffer
  • prio: If POSIX Prioritized IO is supported, then the operation will be prioritized at the process's priority level minus prio
  • sigev_notify: Determines how you will be notified of event completion.
  • opcode: This field is only used for lio_listio. It determines which operation to use for this individual aiocb

Examples

Create an AioCb from a mutable slice and read into it.

const INITIAL: &[u8] = b"abcdef123456";
const LEN: usize = 4;
let mut rbuf = vec![0; LEN];
let mut f = tempfile().unwrap();
f.write_all(INITIAL).unwrap();
{
    let mut aiocb = AioCb::from_mut_slice( f.as_raw_fd(),
        2,   //offset
        &mut rbuf,
        0,   //priority
        SigevNotify::SigevNone,
        LioOpcode::LIO_NOP);
    aiocb.read().unwrap();
    while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) {
        thread::sleep(time::Duration::from_millis(10));
    }
    assert_eq!(aiocb.aio_return().unwrap() as usize, LEN);
}
assert_eq!(rbuf, b"cdef");

[src]

Constructs a new AioCb from a Bytes object.

Unlike from_slice, this method returns a structure suitable for placement on the heap. It may be used for write operations, but not read operations.

Parameters

  • fd: File descriptor. Required for all aio functions.
  • offs: File offset
  • buf: A shared memory buffer
  • prio: If POSIX Prioritized IO is supported, then the operation will be prioritized at the process's priority level minus prio
  • sigev_notify: Determines how you will be notified of event completion.
  • opcode: This field is only used for lio_listio. It determines which operation to use for this individual aiocb

Examples

Create an AioCb from a Bytes object and use it for writing.

let wbuf = Bytes::from(&b"CDEF"[..]);
let mut f = tempfile().unwrap();
let mut aiocb = AioCb::from_bytes( f.as_raw_fd(),
    2,   //offset
    wbuf.clone(),
    0,   //priority
    SigevNotify::SigevNone,
    LioOpcode::LIO_NOP);
aiocb.write().unwrap();
while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) {
    thread::sleep(time::Duration::from_millis(10));
}
assert_eq!(aiocb.aio_return().unwrap() as usize, wbuf.len());

[src]

Constructs a new AioCb from a BytesMut object.

Unlike from_mut_slice, this method returns a structure suitable for placement on the heap. It may be used for both reads and writes.

Parameters

  • fd: File descriptor. Required for all aio functions.
  • offs: File offset
  • buf: An owned memory buffer
  • prio: If POSIX Prioritized IO is supported, then the operation will be prioritized at the process's priority level minus prio
  • sigev_notify: Determines how you will be notified of event completion.
  • opcode: This field is only used for lio_listio. It determines which operation to use for this individual aiocb

Examples

Create an AioCb from a BytesMut and use it for reading. In this example the AioCb is stack-allocated, so we could've used from_mut_slice instead.

const INITIAL: &[u8] = b"abcdef123456";
const LEN: usize = 4;
let rbuf = BytesMut::from(vec![0; LEN]);
let mut f = tempfile().unwrap();
f.write_all(INITIAL).unwrap();
let mut aiocb = AioCb::from_bytes_mut( f.as_raw_fd(),
    2,   //offset
    rbuf,
    0,   //priority
    SigevNotify::SigevNone,
    LioOpcode::LIO_NOP);
aiocb.read().unwrap();
while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) {
    thread::sleep(time::Duration::from_millis(10));
}
assert_eq!(aiocb.aio_return().unwrap() as usize, LEN);
let buffer = aiocb.into_buffer();
const EXPECT: &[u8] = b"cdef";
assert_eq!(buffer.bytes_mut().unwrap(), EXPECT);

[src]

Constructs a new AioCb from a mutable raw pointer

Unlike from_mut_slice, this method returns a structure suitable for placement on the heap. It may be used for both reads and writes. Due to its unsafety, this method is not recommended. It is most useful when heap allocation is required but for some reason the data cannot be converted to a BytesMut.

Parameters

  • fd: File descriptor. Required for all aio functions.
  • offs: File offset
  • buf: Pointer to the memory buffer
  • len: Length of the buffer pointed to by buf
  • prio: If POSIX Prioritized IO is supported, then the operation will be prioritized at the process's priority level minus prio
  • sigev_notify: Determines how you will be notified of event completion.
  • opcode: This field is only used for lio_listio. It determines which operation to use for this individual aiocb

Safety

The caller must ensure that the storage pointed to by buf outlives the AioCb. The lifetime checker can't help here.

[src]

Constructs a new AioCb from a raw pointer.

Unlike from_slice, this method returns a structure suitable for placement on the heap. Due to its unsafety, this method is not recommended. It is most useful when heap allocation is required but for some reason the data cannot be converted to a Bytes.

Parameters

  • fd: File descriptor. Required for all aio functions.
  • offs: File offset
  • buf: Pointer to the memory buffer
  • len: Length of the buffer pointed to by buf
  • prio: If POSIX Prioritized IO is supported, then the operation will be prioritized at the process's priority level minus prio
  • sigev_notify: Determines how you will be notified of event completion.
  • opcode: This field is only used for lio_listio. It determines which operation to use for this individual aiocb

Safety

The caller must ensure that the storage pointed to by buf outlives the AioCb. The lifetime checker can't help here.

[src]

Like from_mut_slice, but works on constant slices rather than mutable slices.

An AioCb created this way cannot be used with read, and its LioOpcode cannot be set to LIO_READ. This method is useful when writing a const buffer with AioCb::write, since from_mut_slice can't work with const buffers.

Examples

Construct an AioCb from a slice and use it for writing.

const WBUF: &[u8] = b"abcdef123456";
let mut f = tempfile().unwrap();
let mut aiocb = AioCb::from_slice( f.as_raw_fd(),
    2,   //offset
    WBUF,
    0,   //priority
    SigevNotify::SigevNone,
    LioOpcode::LIO_NOP);
aiocb.write().unwrap();
while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) {
    thread::sleep(time::Duration::from_millis(10));
}
assert_eq!(aiocb.aio_return().unwrap() as usize, WBUF.len());

[src]

Consumes the aiocb and returns its inner Buffer, if any.

This method is especially useful when reading into a BytesMut, because that type does not support shared ownership.

[src]

Update the notification settings for an existing aiocb

[src]

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 = Bytes::from(&b"CDEF"[..]);
let mut f = tempfile().unwrap();
let mut aiocb = AioCb::from_bytes( f.as_raw_fd(),
    2,   //offset
    wbuf.clone(),
    0,   //priority
    SigevNotify::SigevNone,
    LioOpcode::LIO_NOP);
aiocb.write().unwrap();
let cs = aiocb.cancel().unwrap();
if cs == AioCancelStat::AioNotCanceled {
    while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) {
        thread::sleep(time::Duration::from_millis(10));
    }
}
// Must call `aio_return`, but ignore the result
let _ = aiocb.aio_return();

References

aio_cancel

[src]

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 = AioCb::from_slice( f.as_raw_fd(),
    2,   //offset
    WBUF,
    0,   //priority
    SigevNotify::SigevNone,
    LioOpcode::LIO_NOP);
aiocb.write().unwrap();
while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) {
    thread::sleep(time::Duration::from_millis(10));
}
assert_eq!(aiocb.aio_return().unwrap() as usize, WBUF.len());

References

aio_error

[src]

An asynchronous version of fsync(2).

References

aio_fsync

[src]

Returns the aiocb's LioOpcode field

If the value cannot be represented as an LioOpcode, returns None instead.

[src]

Returns the requested length of the aio operation in bytes

This method returns the requested length of the operation. To get the number of bytes actually read or written by a completed operation, use aio_return instead.

[src]

Returns the file offset stored in the AioCb

[src]

Returns the priority of the AioCb

[src]

Asynchronously reads from a file descriptor into a buffer

References

aio_read

[src]

Returns the SigEvent stored in the AioCb

[src]

Retrieve return status of an asynchronous operation.

Should only be called once for each AioCb, after AioCb::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

[src]

Asynchronously writes from a buffer to a file descriptor

References

aio_write

Trait Implementations

impl<'a> Debug for AioCb<'a>
[src]

[src]

Formats the value using the given formatter. Read more

impl<'a> Drop for AioCb<'a>
[src]

[src]

If the AioCb has no remaining state in the kernel, just drop it. Otherwise, dropping constitutes a resource leak, which is an error