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>
impl<B: PollBackend> Engine<B>
Sourcepub fn with_backend(backend: B, fanout: usize) -> Self
pub fn with_backend(backend: B, fanout: usize) -> Self
Create a new Engine instance with the given backend.
§Arguments
backend- The polling backend implementationfanout- Maximum concurrent operations (0 for no limit)
Sourcepub fn add_timer(&mut self, timer: EngineBaseTimer) -> TimerId
pub fn add_timer(&mut self, timer: EngineBaseTimer) -> TimerId
Sourcepub fn remove_timer(&mut self, id: TimerId)
pub fn remove_timer(&mut self, id: TimerId)
Sourcepub fn fire_timers(&mut self)
pub fn fire_timers(&mut self)
Fire all expired timers
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the engine is running
Sourcepub fn add_client(
&mut self,
client: Box<dyn EngineClient>,
) -> Result<ClientId, EngineError>
pub fn add_client( &mut self, client: Box<dyn EngineClient>, ) -> Result<ClientId, EngineError>
Sourcepub fn remove_client(&mut self, id: ClientId)
pub fn remove_client(&mut self, id: ClientId)
Sourcepub fn update_client_events(
&mut self,
client_id: ClientId,
) -> Result<(), EngineError>
pub fn update_client_events( &mut self, client_id: ClientId, ) -> Result<(), EngineError>
Update client event interests
Sourcepub fn evloop_acquire(&mut self)
pub fn evloop_acquire(&mut self)
Increment the event loop reference count. While refcnt > 0, the engine loop stays alive.
Sourcepub fn evloop_release(&mut self)
pub fn evloop_release(&mut self)
Decrement the event loop reference count. When refcnt reaches 0, the engine stops.
Sourcepub fn client_count(&self) -> usize
pub fn client_count(&self) -> usize
Get the number of registered clients.
Sourcepub fn timerq(&self) -> &TimerQueue
pub fn timerq(&self) -> &TimerQueue
Get the timer queue (immutable).
Sourcepub fn timerq_mut(&mut self) -> &mut TimerQueue
pub fn timerq_mut(&mut self) -> &mut TimerQueue
Get the timer queue (mutable).
Sourcepub fn start_all_clients(&mut self) -> Result<()>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more