pub struct QueueWatcher { /* private fields */ }Expand description
A file descriptor for event-loop integration.
This type wraps a file descriptor that will signal readability when there are events to be dispatched on one or more queues.
You can construct this type by calling Connection::create_watcher,
Queue::create_watcher, or BorrowedQueue::create_watcher.
The contained file descriptor is opaque. You should not interact with it except by polling it for readability.
Once the file descriptor signals readability, the application should
- dispatch the queue(s) by calling
Queue::dispatch_pending, - reset the readability by calling
QueueWatcher::reset, - flush outgoing requests by calling
Connection::flush, - wait for the file descriptor to become readable again.
If not all events were dispatched before calling QueueWatcher::reset, then the
file descriptor will become readable again immediately after being reset.
§Example
let lib = Libwayland::open().unwrap();
let con = lib.connect_to_default_display().unwrap();
let queue = con.create_queue(c"queue name");
let watcher = queue.create_watcher().unwrap();
let token = mio::Token(0);
let mut events = mio::Events::with_capacity(2);
let mut poll = mio::Poll::new().unwrap();
poll
.registry()
.register(&mut SourceFd(&watcher.as_raw_fd()), token, Interest::READABLE)
.unwrap();
// register other application file descriptors
loop {
// flush outgoing messages before going to sleep
con.flush().unwrap();
poll.poll(&mut events, None).unwrap();
for event in events.iter() {
if event.token() == token {
// dispatch new events
queue.dispatch_pending().unwrap();
// reset the watcher
watcher.reset().unwrap();
}
// handle other file descriptors
}
events.clear();
}Implementations§
Source§impl QueueWatcher
impl QueueWatcher
Sourcepub fn reset(&self) -> Result<()>
pub fn reset(&self) -> Result<()>
Resets the file descriptor readability.
The file descriptor will become readable again when there are events to be dispatched.
Examples found in repository?
examples/poll-integration/main.rs (line 41)
11fn main() {
12 let lib = Libwayland::open().unwrap();
13 let con = lib.connect_to_default_display().unwrap();
14 let queue = con.create_local_queue(c"poll-integration");
15
16 // The watcher exposes a file descriptor that will become readable when the queue
17 // has new events.
18 let watcher = queue.create_watcher().unwrap();
19 let token = Token(0);
20
21 create_sync(&queue, 1);
22
23 let mut events = mio::Events::with_capacity(2);
24 let mut poll = mio::Poll::new().unwrap();
25 poll.registry()
26 .register(
27 &mut SourceFd(&watcher.as_raw_fd()),
28 token,
29 Interest::READABLE,
30 )
31 .unwrap();
32
33 loop {
34 // Flush requests before polling.
35 con.flush().unwrap();
36 poll.poll(&mut events, None).unwrap();
37 for event in events.iter() {
38 if event.token() == token {
39 queue.dispatch_pending().unwrap();
40 // Reset the watcher to clear the readability status.
41 watcher.reset().unwrap();
42 }
43 }
44 events.clear();
45 }
46}Trait Implementations§
Source§impl AsFd for QueueWatcher
impl AsFd for QueueWatcher
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Borrows the file descriptor. Read more
Source§impl AsRawFd for &QueueWatcher
impl AsRawFd for &QueueWatcher
Source§impl AsRawFd for QueueWatcher
impl AsRawFd for QueueWatcher
Source§impl Clone for QueueWatcher
impl Clone for QueueWatcher
Source§fn clone(&self) -> QueueWatcher
fn clone(&self) -> QueueWatcher
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for QueueWatcher
impl !RefUnwindSafe for QueueWatcher
impl Send for QueueWatcher
impl Sync for QueueWatcher
impl Unpin for QueueWatcher
impl !UnwindSafe for QueueWatcher
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