Skip to main content

EventFd

Struct EventFd 

Source
pub struct EventFd(/* private fields */);
Expand description

FD eventfd (cf. eventfd2(2)).

Encapsule un compteur kernel 64 bits exposé comme descripteur de fichier. Pattern privilégié pour les notifications légères inter-threads ou inter-processus, et pour l’intégration avec io_uring (wakeup du reactor).

La fermeture du FD est automatique à la destruction (RAII via [OwnedFd]).

Implementations§

Source§

impl EventFd

Source

pub fn as_fd(&self) -> BorrowedFd<'_>

Vue empruntée du FD sous-jacent.

Utile pour passer le FD à d’autres syscalls (poll, io_uring…) sans transférer l’ownership.

Source

pub fn into_fd(self) -> OwnedFd

Consomme le EventFd et restitue le [OwnedFd] sous-jacent.

Source

pub fn read(&self) -> Result<u64, Errno>

Lit la valeur courante du compteur.

Mode normal (sans SEMAPHORE) : retourne la valeur courante et remet le compteur à zéro. Bloque si le compteur est zéro (sauf si NONBLOCK est positionné).

Mode sémaphore (avec SEMAPHORE) : retourne 1 et décrémente de 1. Bloque si le compteur est zéro.

§Errors
  • EAGAIN : compteur à zéro et le FD est en mode non-bloquant.
  • EINTR : interrompu par un signal (ADR-021 convention 2 : pas de retry automatique).
  • EBADF : FD invalide (ne se produit pas si EventFd bien formé).
§Examples
use air_sys_syscall::ipc::eventfd2;
use air_sys_types::EventFdFlags;

let efd = eventfd2(0, EventFdFlags::empty()).expect("eventfd2");
efd.write(5).expect("write");
let val = efd.read().expect("read");
assert_eq!(val, 5);
Source

pub fn write(&self, value: u64) -> Result<(), Errno>

Incrémente le compteur de value.

Bloque si le compteur atteindrait u64::MAX - 1 (espace épuisé). Retourne immédiatement EAGAIN si non-bloquant.

§Parameters
  • value : incrément. La valeur maximale autorisée par incrémentation est u64::MAX - 1 ; u64::MAX est interdit par le kernel.
§Errors
  • EINVAL : value == u64::MAX (débordement interdit).
  • EAGAIN : le FD est non-bloquant et l’incrément bloquerait.
  • EINTR : interrompu par un signal (pas de retry automatique).
§Examples
use air_sys_syscall::ipc::eventfd2;
use air_sys_types::EventFdFlags;

let efd = eventfd2(0, EventFdFlags::empty()).expect("eventfd2");
efd.write(1).expect("write notification");

Trait Implementations§

Source§

impl Debug for EventFd

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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