Skip to content

Commit

Permalink
backend: delete dead clients from epoll
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Jun 25, 2024
1 parent 48e74e9 commit 6885222
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions wayland-backend/src/rs/server_impl/common_poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<D> InnerBackend<D> {
data: &mut D,
client_id: InnerClientId,
) -> std::io::Result<usize> {
let ret = self.dispatch_events_for(data, client_id);
let ret = self.dispatch_events_for(data, self.poll_fd(), client_id);
let cleanup = self.state.lock().unwrap().cleanup();
cleanup(&self.handle(), data);
ret
Expand All @@ -94,7 +94,7 @@ impl<D> InnerBackend<D> {
for event in events.iter() {
let id = InnerClientId::from_u64(event.data.u64());
// remove the cb while we call it, to gracefully handle reentrancy
if let Ok(count) = self.dispatch_events_for(data, id) {
if let Ok(count) = self.dispatch_events_for(data, poll_fd, id) {
dispatched += count;
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ impl<D> InnerBackend<D> {
for event in events.iter().take(nevents) {
let id = InnerClientId::from_u64(event.udata() as u64);
// remove the cb while we call it, to gracefully handle reentrancy
if let Ok(count) = self.dispatch_events_for(data, id) {
if let Ok(count) = self.dispatch_events_for(data, poll_fd, id) {
dispatched += count;
}
}
Expand All @@ -142,6 +142,7 @@ impl<D> InnerBackend<D> {
pub(crate) fn dispatch_events_for(
&self,
data: &mut D,
poll_fd: BorrowedFd<'_>,
client_id: InnerClientId,
) -> std::io::Result<usize> {
let mut dispatched = 0;
Expand All @@ -160,7 +161,36 @@ impl<D> InnerBackend<D> {
return Err(e);
}
}
Err(e) => return Err(e),
Err(e) => {
#[cfg(any(target_os = "linux", target_os = "android"))]
{
epoll::delete(poll_fd, client)?;
}

#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "macos"
))]
{
use rustix::event::kqueue::*;
use std::os::unix::io::{AsFd, AsRawFd};

let evt = Event::new(
EventFilter::Read(client.as_fd().as_raw_fd()),
EventFlags::DELETE,
client_id.as_u64() as isize,
);

let mut events = Vec::new();
unsafe {
kevent(poll_fd, &[evt], &mut events, None).map(|_| ())?;
}
}
return Err(e);
}
};
dispatched += 1;
if same_interface(object.interface, &WL_DISPLAY_INTERFACE) {
Expand Down

0 comments on commit 6885222

Please sign in to comment.