rdp: disconnect update listener when the client is gone

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2024-10-30 16:43:19 +04:00
parent 3b282c440a
commit 2432ee97f3
2 changed files with 16 additions and 5 deletions

View File

@ -2,7 +2,10 @@
use crate::win32::Fd;
#[cfg(unix)]
use std::os::unix::net::UnixStream;
use std::{convert::TryFrom, sync::RwLock};
use std::{
convert::TryFrom,
sync::{Arc, RwLock},
};
#[cfg(windows)]
use uds_windows::UnixStream;
#[cfg(unix)]
@ -50,7 +53,7 @@ pub trait Console {
}
#[derive(derivative::Derivative)]
#[derivative(Debug)]
#[derivative(Debug, Clone)]
pub struct Console {
#[derivative(Debug = "ignore")]
pub proxy: ConsoleProxy<'static>,
@ -60,7 +63,7 @@ pub struct Console {
pub mouse: MouseProxy<'static>,
#[derivative(Debug = "ignore")]
pub multi_touch: MultiTouchProxy<'static>,
listener: RwLock<Option<Connection>>,
listener: Arc<RwLock<Option<Connection>>>,
#[cfg(windows)]
peer_pid: u32,
}
@ -83,7 +86,7 @@ impl Console {
keyboard,
mouse,
multi_touch,
listener: RwLock::new(None),
listener: Arc::new(RwLock::new(None)),
#[cfg(windows)]
peer_pid,
})

View File

@ -30,6 +30,13 @@ pub struct DisplayHandler {
struct DisplayUpdates {
receiver: queue::Receiver,
console: Console,
}
impl Drop for DisplayUpdates {
fn drop(&mut self) {
self.console.unregister_listener();
}
}
impl DisplayHandler {
@ -52,7 +59,8 @@ impl DisplayHandler {
#[cfg(any(windows, unix))]
self.console.set_map_listener(listener.clone()).await?;
Ok(DisplayUpdates { receiver })
let console = self.console.clone();
Ok(DisplayUpdates { receiver, console })
}
}