mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-05-11 18:36:11 +02:00
parent
419bb3f0b0
commit
61cdb60362
2 changed files with 41 additions and 3 deletions
31
src/ipc.rs
31
src/ipc.rs
|
@ -280,6 +280,8 @@ pub enum Data {
|
||||||
not(any(target_os = "android", target_os = "ios"))
|
not(any(target_os = "android", target_os = "ios"))
|
||||||
))]
|
))]
|
||||||
ControllingSessionCount(usize),
|
ControllingSessionCount(usize),
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
PortForwardSessionCount(Option<usize>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
|
@ -692,6 +694,25 @@ async fn handle(data: Data, stream: &mut Connection) {
|
||||||
// This branch is left blank for unification and further use.
|
// This branch is left blank for unification and further use.
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
Data::PortForwardSessionCount(c) => match c {
|
||||||
|
None => {
|
||||||
|
let count = crate::server::AUTHED_CONNS
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.filter(|c| c.conn_type == crate::server::AuthConnType::PortForward)
|
||||||
|
.count();
|
||||||
|
allow_err!(
|
||||||
|
stream
|
||||||
|
.send(&Data::PortForwardSessionCount(Some(count)))
|
||||||
|
.await
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// Port forward session count is only a get value.
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1201,6 +1222,16 @@ pub async fn notify_server_to_check_hwcodec() -> ResultType<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
pub async fn get_port_forward_session_count(ms_timeout: u64) -> ResultType<usize> {
|
||||||
|
let mut c = connect(ms_timeout, "").await?;
|
||||||
|
c.send(&Data::PortForwardSessionCount(None)).await?;
|
||||||
|
if let Some(Data::PortForwardSessionCount(Some(count))) = c.next_timeout(ms_timeout).await? {
|
||||||
|
return Ok(count);
|
||||||
|
}
|
||||||
|
bail!("Failed to get port forward session count");
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "hwcodec")]
|
#[cfg(feature = "hwcodec")]
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
|
|
|
@ -573,7 +573,11 @@ async fn run_service(_arguments: Vec<OsString>) -> ResultType<()> {
|
||||||
let current_active_session = unsafe { get_current_session(share_rdp()) };
|
let current_active_session = unsafe { get_current_session(share_rdp()) };
|
||||||
if session_id != current_active_session {
|
if session_id != current_active_session {
|
||||||
session_id = current_active_session;
|
session_id = current_active_session;
|
||||||
h_process = launch_server(session_id, true).await.unwrap_or(NULL);
|
// https://github.com/rustdesk/rustdesk/discussions/10039
|
||||||
|
let count = ipc::get_port_forward_session_count(1000).await.unwrap_or(0);
|
||||||
|
if count == 0 {
|
||||||
|
h_process = launch_server(session_id, true).await.unwrap_or(NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let res = timeout(super::SERVICE_INTERVAL, incoming.next()).await;
|
let res = timeout(super::SERVICE_INTERVAL, incoming.next()).await;
|
||||||
|
@ -622,8 +626,11 @@ async fn run_service(_arguments: Vec<OsString>) -> ResultType<()> {
|
||||||
if tmp != session_id && stored_usid != Some(session_id) {
|
if tmp != session_id && stored_usid != Some(session_id) {
|
||||||
log::info!("session changed from {} to {}", session_id, tmp);
|
log::info!("session changed from {} to {}", session_id, tmp);
|
||||||
session_id = tmp;
|
session_id = tmp;
|
||||||
send_close_async("").await.ok();
|
let count = ipc::get_port_forward_session_count(1000).await.unwrap_or(0);
|
||||||
close_sent = true;
|
if count == 0 {
|
||||||
|
send_close_async("").await.ok();
|
||||||
|
close_sent = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let mut exit_code: DWORD = 0;
|
let mut exit_code: DWORD = 0;
|
||||||
if h_process.is_null()
|
if h_process.is_null()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue