pub struct LoopRef(/* private fields */);
Expand description
Implementations§
source§impl LoopRef
impl LoopRef
pub fn as_raw(&self) -> &pw_loop
pub fn as_raw_ptr(&self) -> *mut pw_loop
sourcepub fn fd(&self) -> BorrowedFd<'_>
pub fn fd(&self) -> BorrowedFd<'_>
Get the file descriptor backing this loop.
sourcepub unsafe fn enter(&self)
pub unsafe fn enter(&self)
Enter a loop
Start an iteration of the loop. This function should be called before calling iterate and is typically used to capture the thread that this loop will run in.
§Safety
Each call of enter
must be paired with a call of leave
.
sourcepub unsafe fn leave(&self)
pub unsafe fn leave(&self)
Leave a loop
Ends the iteration of a loop. This should be called after calling iterate.
§Safety
Each call of leave
must be paired with a call of enter
.
sourcepub fn iterate(&self, timeout: Duration) -> i32
pub fn iterate(&self, timeout: Duration) -> i32
Perform one iteration of the loop.
An optional timeout can be provided. 0 for no timeout, -1 for infinite timeout.
This function will block up to the provided timeout and then dispatch the fds with activity. The number of dispatched fds is returned.
This will automatically call Self::enter()
on the loop before iterating, and Self::leave()
afterwards.
§Panics
This function will panic if the provided timeout as milliseconds does not fit inside a
c_int
integer.
sourcepub unsafe fn iterate_unguarded(&self, timeout: Duration) -> i32
pub unsafe fn iterate_unguarded(&self, timeout: Duration) -> i32
A variant of iterate()
that does not call Self::enter()
and Self::leave()
on the loop.
§Safety
Before calling this, Self::enter()
must be called, and Self::leave()
must be called afterwards.
sourcepub fn add_io<I, F>(
&self,
io: I,
event_mask: IoFlags,
callback: F
) -> IoSource<'_, I>
pub fn add_io<I, F>( &self, io: I, event_mask: IoFlags, callback: F ) -> IoSource<'_, I>
Register some type of IO object with a callback that is called when reading/writing on the IO object is available.
The specified event_mask
determines whether to trigger when either input, output, or any of the two is available.
The returned IoSource needs to take ownership of the IO object, but will provide a reference to the callback when called.
sourcepub fn add_idle<F>(&self, enabled: bool, callback: F) -> IdleSource<'_>where
F: Fn() + 'static,
pub fn add_idle<F>(&self, enabled: bool, callback: F) -> IdleSource<'_>where
F: Fn() + 'static,
Register a callback to be called whenever the loop is idle.
This can be enabled and disabled as needed with the enabled
parameter,
and also with the enable
method on the returned source.
sourcepub fn add_signal_local<F>(
&self,
signal: Signal,
callback: F
) -> SignalSource<'_>
pub fn add_signal_local<F>( &self, signal: Signal, callback: F ) -> SignalSource<'_>
Register a signal with a callback that is called when the signal is sent.
For example, this can be used to quit the loop when the process receives the SIGTERM
signal.
sourcepub fn add_event<F>(&self, callback: F) -> EventSource<'_>
pub fn add_event<F>(&self, callback: F) -> EventSource<'_>
Register a new event with a callback that is called when the event happens.
The returned EventSource
can be used to trigger the event.
sourcepub fn add_timer<F>(&self, callback: F) -> TimerSource<'_>
pub fn add_timer<F>(&self, callback: F) -> TimerSource<'_>
Register a timer with the loop with a callback that is called after the timer expired.
The timer will start out inactive, and the returned TimerSource
can be used to arm the timer, or disarm it again.
The callback will be provided with the number of timer expirations since the callback was last called.