QueueWatcher

Struct QueueWatcher 

Source
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

  1. dispatch the queue(s) by calling Queue::dispatch_pending,
  2. reset the readability by calling QueueWatcher::reset,
  3. flush outgoing requests by calling Connection::flush,
  4. 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

Source

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

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl AsRawFd for &QueueWatcher

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl AsRawFd for QueueWatcher

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Clone for QueueWatcher

Source§

fn clone(&self) -> QueueWatcher

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.