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 44)
14fn main() {
15 let lib = Libwayland::open().unwrap();
16 let con = lib.connect_to_default_display().unwrap();
17 let queue = con.create_local_queue(c"poll-integration");
18
19 // The watcher exposes a file descriptor that will become readable when the queue
20 // has new events.
21 let watcher = queue.create_watcher().unwrap();
22 let token = Token(0);
23
24 create_sync(&queue, 1);
25
26 let mut events = mio::Events::with_capacity(2);
27 let mut poll = mio::Poll::new().unwrap();
28 poll.registry()
29 .register(
30 &mut SourceFd(&watcher.as_raw_fd()),
31 token,
32 Interest::READABLE,
33 )
34 .unwrap();
35
36 loop {
37 // Flush requests before polling.
38 con.flush().unwrap();
39 poll.poll(&mut events, None).unwrap();
40 for event in events.iter() {
41 if event.token() == token {
42 queue.dispatch_pending().unwrap();
43 // Reset the watcher to clear the readability status.
44 watcher.reset().unwrap();
45 }
46 }
47 events.clear();
48 }
49}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
Auto Trait Implementations§
impl !RefUnwindSafe for QueueWatcher
impl !UnwindSafe for QueueWatcher
impl Forget for QueueWatcher
impl Freeze for QueueWatcherwhere
*const ArcInner<QueueWatcherData> is !null: Freeze,
PhantomData<ArcInner<QueueWatcherData>>: Freeze,
impl Move for QueueWatcher
impl Send for QueueWatcher
impl Sync for QueueWatcher
impl Unpin for QueueWatcher
impl UnsafeUnpin for QueueWatcherwhere
*const ArcInner<QueueWatcherData> is !null: UnsafeUnpin,
PhantomData<ArcInner<QueueWatcherData>>: 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