Acceptor

Struct Acceptor 

Source
pub struct Acceptor { /* private fields */ }
Expand description

A file-system acceptor for wayland connections.

This represents a socket in the XDG_RUNTIME_DIR directory. Its name follows the usual wayland-N scheme.

§Example

let acceptor = Acceptor::new(1000, false).unwrap();
loop {
    let con = acceptor.accept().unwrap().unwrap();
    handle_wayland_connection(con);
}

Implementations§

Source§

impl Acceptor

Source

pub fn new( max_tries: u32, non_blocking: bool, ) -> Result<Rc<Self>, AcceptorError>

Creates a new acceptor.

This will try to allocate the socket wayland-N in the XDG_RUNTIME_DIR directory. The function starts with N = 1 and then increments N until it finds an unused socket. The maximum value of N is determined by the max_tries parameter.

If non_blocking is true, the created socket will be non-blocking, which means that Acceptor::accept can return Ok(None). In this case you should use a mechanism such as epoll to wait for new connections on the socket.

§Example
let acceptor = Acceptor::new(1000, false).unwrap();
loop {
    let con = acceptor.accept().unwrap().unwrap();
    handle_wayland_connection(con);
}
Source

pub fn display(&self) -> &str

Returns the display name of this acceptor, for example, wayland-1.

§Example
let acceptor = Acceptor::new(1000, false).unwrap();
eprintln!("{}", acceptor.display());
Source

pub fn socket(&self) -> BorrowedFd<'_>

Returns the socket file descriptor of this acceptor.

This can be used to asynchronously wait for new connections. The returned file descriptor should not be used to modify the file description. Otherwise, the behavior is unspecified.

§Example
let acceptor = Acceptor::new(1000, true).unwrap();
loop {
    wait_for_descriptor_to_become_readable(acceptor.socket());
    let con = acceptor.accept().unwrap().unwrap();
    handle_wayland_connection(con);
}
Source

pub unsafe fn setenv(&self)

Sets the WAYLAND_DISPLAY environment variable to the display of this acceptor.

§Safety

This function is unsafe because it calls set_var.

§Example
let acceptor = Acceptor::new(1000, false).unwrap();
unsafe {
    acceptor.setenv();
}
Source

pub fn accept(&self) -> Result<Option<OwnedFd>, AcceptorError>

Accepts a new connection.

This can return None if and only if this acceptor is non-blocking and there is currently no client trying to connect to this acceptor.

§Example
let acceptor = Acceptor::new(1000, false).unwrap();
loop {
    let con = acceptor.accept().unwrap().unwrap();
    handle_wayland_connection(con);
}

Trait Implementations§

Source§

impl AsFd for Acceptor

Source§

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

Borrows the file descriptor. 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> 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, 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.