Skip to main content

Engine

Struct Engine 

Source
pub struct Engine<B: PollBackend> { /* private fields */ }
Expand description

The main I/O event loop engine.

The Engine manages:

  • Timer scheduling and expiration
  • Client registration and event monitoring
  • The main event loop
  • Fanout control (maximum concurrent operations)

§Example

use consortium::engine::{Engine, EngineBaseTimer, EngineClient, PollBackend, ClientId, FANOUT_UNLIMITED};
use std::os::unix::io::RawFd;

// Engine requires a concrete PollBackend implementation.
// See NullBackend in tests for a minimal example.

Implementations§

Source§

impl<B: PollBackend> Engine<B>

Source

pub fn with_backend(backend: B, fanout: usize) -> Self

Create a new Engine instance with the given backend.

§Arguments
  • backend - The polling backend implementation
  • fanout - Maximum concurrent operations (0 for no limit)
Source

pub fn add_timer(&mut self, timer: EngineBaseTimer) -> TimerId

Add a timer and return its ID

§Arguments
  • timer - The timer to add
Source

pub fn remove_timer(&mut self, id: TimerId)

Remove a timer by ID

§Arguments
  • id - The timer ID to remove
Source

pub fn fire_timers(&mut self)

Fire all expired timers

Source

pub fn run(&mut self, timeout: Option<f64>) -> Result<(), EngineError>

Run the engine event loop

§Arguments
  • timeout - Optional timeout in seconds (None for no limit)
Source

pub fn abort(&mut self, kill: bool)

Abort the engine

§Arguments
  • kill - If true, force kill all clients
Source

pub fn is_running(&self) -> bool

Check if the engine is running

Source

pub fn exited(&self) -> bool

Check if the engine has exited

Source

pub fn add_client( &mut self, client: Box<dyn EngineClient>, ) -> Result<ClientId, EngineError>

Add a client to the engine

§Arguments
  • client - The client to add
Source

pub fn remove_client(&mut self, id: ClientId)

Remove a client by ID

§Arguments
  • id - The client ID to remove
Source

pub fn fanout(&self) -> usize

Get the fanout value

Source

pub fn update_client_events( &mut self, client_id: ClientId, ) -> Result<(), EngineError>

Update client event interests

Source

pub fn stop(&mut self)

Stop the engine event loop.

Source

pub fn evloop_acquire(&mut self)

Increment the event loop reference count. While refcnt > 0, the engine loop stays alive.

Source

pub fn evloop_release(&mut self)

Decrement the event loop reference count. When refcnt reaches 0, the engine stops.

Source

pub fn client_count(&self) -> usize

Get the number of registered clients.

Source

pub fn timerq(&self) -> &TimerQueue

Get the timer queue (immutable).

Source

pub fn timerq_mut(&mut self) -> &mut TimerQueue

Get the timer queue (mutable).

Source

pub fn start_all_clients(&mut self) -> Result<()>

Start all registered clients.

Auto Trait Implementations§

§

impl<B> !RefUnwindSafe for Engine<B>

§

impl<B> !Sync for Engine<B>

§

impl<B> !UnwindSafe for Engine<B>

§

impl<B> Freeze for Engine<B>
where B: Freeze,

§

impl<B> Send for Engine<B>

§

impl<B> Unpin for Engine<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for Engine<B>
where B: UnsafeUnpin,

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, !>

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.