fix unexpected return via whitelist block by raii
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
6cb35ae01e
commit
59cfb44c08
@ -241,12 +241,12 @@ impl Connection {
|
||||
id: i32,
|
||||
server: super::ServerPtrWeak,
|
||||
) {
|
||||
let _raii_id = raii::ConnectionID::new(id);
|
||||
let hash = Hash {
|
||||
salt: Config::get_salt(),
|
||||
challenge: Config::get_auto_password(6),
|
||||
..Default::default()
|
||||
};
|
||||
ALIVE_CONNS.lock().unwrap().push(id);
|
||||
let (tx_from_cm_holder, mut rx_from_cm) = mpsc::unbounded_channel::<ipc::Data>();
|
||||
// holding tx_from_cm_holder to avoid cpu burning of rx_from_cm.recv when all sender closed
|
||||
let tx_from_cm = tx_from_cm_holder.clone();
|
||||
@ -627,22 +627,12 @@ impl Connection {
|
||||
conn.post_conn_audit(json!({
|
||||
"action": "close",
|
||||
}));
|
||||
let mut active_conns_lock = ALIVE_CONNS.lock().unwrap();
|
||||
active_conns_lock.retain(|&c| c != id);
|
||||
if let Some(s) = conn.server.upgrade() {
|
||||
let mut s = s.write().unwrap();
|
||||
s.remove_connection(&conn.inner);
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
try_stop_record_cursor_pos();
|
||||
}
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
if active_conns_lock.is_empty() {
|
||||
video_service::reset_resolutions();
|
||||
}
|
||||
#[cfg(all(windows, feature = "virtual_display_driver"))]
|
||||
if active_conns_lock.is_empty() {
|
||||
video_service::try_plug_out_virtual_display();
|
||||
}
|
||||
log::info!("#{} connection loop exited", id);
|
||||
}
|
||||
|
||||
@ -2538,3 +2528,30 @@ impl Drop for Connection {
|
||||
self.release_pressed_modifiers();
|
||||
}
|
||||
}
|
||||
|
||||
mod raii {
|
||||
use super::*;
|
||||
pub struct ConnectionID(i32);
|
||||
|
||||
impl ConnectionID {
|
||||
pub fn new(id: i32) -> Self {
|
||||
ALIVE_CONNS.lock().unwrap().push(id);
|
||||
Self(id)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ConnectionID {
|
||||
fn drop(&mut self) {
|
||||
let mut active_conns_lock = ALIVE_CONNS.lock().unwrap();
|
||||
active_conns_lock.retain(|&c| c != self.0);
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
if active_conns_lock.is_empty() {
|
||||
video_service::reset_resolutions();
|
||||
}
|
||||
#[cfg(all(windows, feature = "virtual_display_driver"))]
|
||||
if active_conns_lock.is_empty() {
|
||||
video_service::try_plug_out_virtual_display();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user