pub struct WakePipe { /* private fields */ }Expand description
Wake notification built on pipe(2).
The pattern is:
- one thread blocks on the read end with
poll(2) - another thread writes one byte to the write end to signal “work exists”
- the waiter drains pending bytes before going back to sleep
Why use a pipe here:
- it gives us a real file descriptor that integrates with
poll(2) - it works on the Unix platforms smolvm targets
- it is simpler than building a custom condvar + timeout scheme around the smoltcp loop and Unix-stream writer
Implementations§
Source§impl WakePipe
impl WakePipe
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a non-blocking wake pipe.
Low-level steps:
pipe() -> create read/write fds
fcntl(F_SETFL) -> add O_NONBLOCK
fcntl(F_SETFD) -> add FD_CLOEXEC
wrap in OwnedFd -> move fd lifetime into Rust ownershipSourcepub fn wake(&self)
pub fn wake(&self)
Signal the waiting side.
Writing one byte is enough. The byte value itself does not matter; only readability of the pipe matters. Multiple writes coalesce naturally into “there is pending wake state”.
Sourcepub fn drain(&self)
pub fn drain(&self)
Drain all pending wake bytes.
This resets the readiness state after a wake. Because the pipe is
non-blocking, read <= 0 means “nothing more to drain right now”.
Sourcepub fn wait(&self, timeout: Option<Duration>) -> Result<bool>
pub fn wait(&self, timeout: Option<Duration>) -> Result<bool>
Wait until the pipe is readable or the timeout elapses.
This is the low-level equivalent of “sleep until another thread signals me or the timeout expires”, but implemented in file-descriptor space so it composes with other polling logic.
Trait Implementations§
Source§impl Clone for WakePipe
impl Clone for WakePipe
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Clone by duplicating both file descriptors.
Each clone refers to the same underlying pipe objects, so waking or draining from any clone affects the shared readiness state.
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more