From 2432ee97f3718efb8e972008dcbfc044374d7844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 30 Oct 2024 16:43:19 +0400 Subject: [PATCH] rdp: disconnect update listener when the client is gone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- qemu-display/src/console.rs | 11 +++++++---- qemu-rdp/src/server/display.rs | 10 +++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/qemu-display/src/console.rs b/qemu-display/src/console.rs index f8593d1..efe29d7 100644 --- a/qemu-display/src/console.rs +++ b/qemu-display/src/console.rs @@ -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>, + listener: Arc>>, #[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, }) diff --git a/qemu-rdp/src/server/display.rs b/qemu-rdp/src/server/display.rs index a7ae36c..520283b 100644 --- a/qemu-rdp/src/server/display.rs +++ b/qemu-rdp/src/server/display.rs @@ -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 }) } }