pub struct WakePipe { /* private fields */ }Expand description
Cross-thread wake notification built on a cross-platform poller.
The pattern is:
- one thread blocks waiting on the poller (optionally alongside registered socket sources)
- another thread calls
WakePipe::waketo unblock it - the waiter resumes; the wake is auto-cleared by the next
wait
Why a poller rather than a self-pipe: polling::Poller::notify() is a
portable cross-thread wakeup that works on Windows (where a pipe(2) is not
pollable by the IOCP/wepoll backend) as well as Unix. The same poller can
have socket sources registered on it, which lets the ICMP/UDP relay loops
wait on “wake OR any flow socket readable” in a single blocking call.
Implementations§
Source§impl WakePipe
impl WakePipe
Create another handle that shares this wake’s underlying poller.
Two WakePipes built this way notify the same waiter: useful when one
loop must wake on either of two logical events (the smoltcp loop wakes on
guest frames or relay data).
Sourcepub fn poller(&self) -> &Arc<Poller>
pub fn poller(&self) -> &Arc<Poller>
The underlying poller, so a caller can register socket sources on it and
block on “this wake OR a socket” in a single wait.
Sourcepub fn wake(&self)
pub fn wake(&self)
Signal the waiting side.
Multiple wakes coalesce: until the waiter next blocks, repeated notifies collapse into a single “there is pending wake state”.
Sourcepub fn drain(&self)
pub fn drain(&self)
Drain pending wake state.
With a poller-backed waker the notification is consumed by wait
itself, so this is a no-op kept for API symmetry with the old self-pipe.
Sourcepub fn wait(&self, timeout: Option<Duration>) -> Result<bool>
pub fn wait(&self, timeout: Option<Duration>) -> Result<bool>
Wait until woken or the timeout elapses.
Returns Ok(true) if the wait ended because of a wake (a notify or a
registered source becoming ready), Ok(false) if the timeout elapsed.
A notify-driven wakeup reports no events (the poller consumes the
notification internally), so a pure wake is detected as either a
non-empty event set or an early return: the wait unblocked before the
requested deadline.