Skip to main content

Token

Struct Token 

Source
pub struct Token<T: Send + 'static> { /* private fields */ }
Expand description

An owned value, plus the identity of the operation the kernel may still be reading or writing through it.

Usually T is an crate::IoBuf the operation reads or writes, but nothing about this type depends on that: M5’s buffer registration reuses the same forget-unless-claimed mechanism to track a registration’s own in-flight uses, where T carries no bytes at all (see RegisteredUse in batch.rs).

Token intentionally holds no reference back to the crate::IoRing that minted its identity: outstanding-operation accounting belongs to the ring (D-4 in DESIGN-NOTES.md), driven by whoever actually pops an IORING_CQE, not by a Token merely being dropped. A dropped, unclaimed Token means the caller has given up on this handle; it says nothing about whether the kernel has finished the operation, which is exactly why dropping it forgets the value instead of freeing it – see Token’s Drop impl.

Implementations§

Source§

impl<T: Send + 'static> Token<T>

Source

pub fn id(&self) -> usize

This token’s UserData identity.

Source

pub fn claim_if(self, completion: &Completion) -> Result<T, Self>

Claim this token’s value if completion names it, or hand it back unchanged otherwise (D-4).

Takes a popped Completion, not a bare usize: Completion has no public constructor, so the only way to produce one is crate::IoRing::try_pop actually observing a real IORING_CQE. Accepting a caller-supplied integer here instead – for example token.claim_if(token.id()) – would let safe code reclaim (and then drop, freeing) a buffer the kernel might still be reading or writing, which is exactly the use-after-free this type exists to prevent. Unlike windows-overlapped-io-sys’s OperationId, there is no storage address to also check on its own – UserData is a value this crate chose – but two different rings each hand out UserData from their own counter starting at zero, so the same value can legitimately occur on both. Requiring completion’s ring identity to match this token’s own (PR #20 review response) is what rules that out: a token can only ever be claimed by a completion popped from the exact ring that minted it.

Trait Implementations§

Source§

impl<T: Send + 'static> Debug for Token<T>

Source§

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

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

impl<T: Send + 'static> Drop for Token<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
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<T> Freeze for Token<T>
where ManuallyDrop<T>: Freeze,

§

impl<T> RefUnwindSafe for Token<T>

§

impl<T> Send for Token<T>
where ManuallyDrop<T>: Send,

§

impl<T> Sync for Token<T>
where ManuallyDrop<T>: Sync,

§

impl<T> Unpin for Token<T>
where ManuallyDrop<T>: Unpin,

§

impl<T> UnsafeUnpin for Token<T>

§

impl<T> UnwindSafe for Token<T>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.