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
impl Acceptor
Sourcepub fn new(
max_tries: u32,
non_blocking: bool,
) -> Result<Rc<Self>, AcceptorError>
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);
}Sourcepub fn display(&self) -> &str
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());Sourcepub fn socket(&self) -> BorrowedFd<'_>
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);
}Sourcepub fn accept(&self) -> Result<Option<OwnedFd>, AcceptorError>
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);
}