Skip to main content

AioCb

Struct AioCb 

Source
pub struct AioCb<'a> { /* private fields */ }
Expand description

AIO Control Block.

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

Implementations§

Source§

impl<'a> AioCb<'a>

Source

pub fn fd(&self) -> i32

Returns the underlying file descriptor associated with the AioCb

Source

pub fn from_fd( fd: i32, prio: i32, sigev_notify: SigevNotify, ) -> Pin<Box<AioCb<'a>>>

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(Errno::EINPROGRESS)) {
    thread::sleep(time::Duration::from_millis(10));
}
aiocb.aio_return().expect("aio_fsync failed late");
Source

pub fn from_mut_slice( fd: i32, offs: i64, buf: &'a mut [u8], prio: i32, sigev_notify: SigevNotify, opcode: LioOpcode, ) -> Pin<Box<AioCb<'a>>>

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.

§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(Errno::EINPROGRESS)) {
        thread::sleep(time::Duration::from_millis(10));
    }
    assert_eq!(aiocb.aio_return().unwrap() as usize, LEN);
}
assert_eq!(rbuf, b"cdef");
Source

pub unsafe fn from_mut_ptr( fd: i32, offs: i64, buf: *mut c_void, len: usize, prio: i32, sigev_notify: SigevNotify, opcode: LioOpcode, ) -> Pin<Box<AioCb<'a>>>

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.

§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.

Source

pub unsafe fn from_ptr( fd: i32, offs: i64, buf: *const c_void, len: usize, prio: i32, sigev_notify: SigevNotify, opcode: LioOpcode, ) -> Pin<Box<AioCb<'a>>>

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.

§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.

Source

pub fn from_slice( fd: i32, offs: i64, buf: &'a [u8], prio: i32, sigev_notify: SigevNotify, opcode: LioOpcode, ) -> Pin<Box<AioCb<'a>>>

Like AioCb::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(Errno::EINPROGRESS)) {
    thread::sleep(time::Duration::from_millis(10));
}
assert_eq!(aiocb.aio_return().unwrap() as usize, WBUF.len());
Source

pub fn set_sigev_notify( self: &mut Pin<Box<AioCb<'a>>>, sigev_notify: SigevNotify, )

Update the notification settings for an existing aiocb

Source

pub fn cancel(self: &mut Pin<Box<AioCb<'a>>>) -> Result<AioCancelStat, Errno>

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

aio_cancel

Source

pub fn error(self: &mut Pin<Box<AioCb<'a>>>) -> Result<(), Errno>

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(Errno::EINPROGRESS)) {
    thread::sleep(time::Duration::from_millis(10));
}
assert_eq!(aiocb.aio_return().unwrap() as usize, WBUF.len());
§References

aio_error

Source

pub fn fsync( self: &mut Pin<Box<AioCb<'a>>>, mode: AioFsyncMode, ) -> Result<(), Errno>

An asynchronous version of fsync(2).

§References

aio_fsync

Source

pub fn lio_opcode(&self) -> Option<LioOpcode>

Returns the aiocb’s LioOpcode field

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

Source

pub fn nbytes(&self) -> usize

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.

Source

pub fn offset(&self) -> i64

Returns the file offset stored in the AioCb

Source

pub fn priority(&self) -> i32

Returns the priority of the AioCb

Source

pub fn read(self: &mut Pin<Box<AioCb<'a>>>) -> Result<(), Errno>

Asynchronously reads from a file descriptor into a buffer

§References

aio_read

Source

pub fn sigevent(&self) -> SigEvent

Returns the SigEvent stored in the AioCb

Source

pub fn aio_return(self: &mut Pin<Box<AioCb<'a>>>) -> Result<isize, Errno>

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

Source

pub fn write(self: &mut Pin<Box<AioCb<'a>>>) -> Result<(), Errno>

Asynchronously writes from a buffer to a file descriptor

§References

aio_write

Trait Implementations§

Source§

impl<'a> Debug for AioCb<'a>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> Drop for AioCb<'a>

Source§

fn drop(&mut self)

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

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for AioCb<'a>

§

impl<'a> RefUnwindSafe for AioCb<'a>

§

impl<'a> Send for AioCb<'a>

§

impl<'a> Sync for AioCb<'a>

§

impl<'a> !Unpin for AioCb<'a>

§

impl<'a> !UnsafeUnpin for AioCb<'a>

§

impl<'a> UnwindSafe for AioCb<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DebugExt<T> for T
where T: Debug,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<A> DynCastExt for A

Source§

fn dyn_cast<T>( self, ) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source>
where A: DynCastExtHelper<T>, T: ?Sized,

Use this to cast from one trait object type to another. Read more
Source§

fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target
where A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>, T: ?Sized,

Use this to upcast a trait to one of its supertraits. Read more
Source§

fn dyn_cast_adv<F, T>( self, ) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source>
where A: DynCastExtAdvHelper<F, T>, F: ?Sized, T: ?Sized,

Use this to cast from one trait object type to another. This method is more customizable than the dyn_cast method. Here you can also specify the “source” trait from which the cast is defined. This can for example allow using casts from a supertrait of the current trait object. Read more
Source§

fn dyn_cast_with_config<C>( self, ) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source>

Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more