From c970e5b22bb67af31b655ab1ca6b7becc01add34 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Wed, 11 Aug 2021 21:08:05 +0800 Subject: [PATCH] shared memory for future usage, but it has permission problem on Windows, not find way to make files writable for all users on Windows --- src/ipc.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/ipc.rs b/src/ipc.rs index cd8abdb9b..b4e11e40a 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -467,3 +467,63 @@ pub async fn get_nat_type(ms_timeout: u64) -> i32 { .await .unwrap_or(Config::get_nat_type()) } + +/* +static mut SHARED_MEMORY: *mut i64 = std::ptr::null_mut(); + +pub fn initialize_shared_memory(create: bool) { + let mut shmem_flink = "shared-memory".to_owned(); + if cfg!(windows) { + let df = "C:\\ProgramData"; + let df = if std::path::Path::new(df).exists() { + df.to_owned() + } else { + std::env::var("TEMP").unwrap_or("C:\\Windows\\TEMP".to_owned()) + }; + let df = format!("{}\\{}", df, *hbb_common::config::APP_NAME.read().unwrap()); + std::fs::create_dir(&df).ok(); + shmem_flink = format!("{}\\{}", df, shmem_flink); + } else { + shmem_flink = Config::ipc_path("").replace("ipc", "") + &shmem_flink; + } + use shared_memory::*; + let shmem = if create { + match ShmemConf::new() + .force_create_flink() + .size(16) + .flink(&shmem_flink) + .create() + { + Err(ShmemError::LinkExists) => ShmemConf::new().flink(&shmem_flink).open(), + Ok(m) => Ok(m), + Err(e) => Err(e), + } + } else { + ShmemConf::new().flink(&shmem_flink).open() + }; + if create { + set_all_perm(&shmem_flink); + } + match shmem { + Ok(shmem) => unsafe { + SHARED_MEMORY = shmem.as_ptr() as *mut i64; + std::mem::forget(shmem); + }, + Err(err) => { + log::error!( + "Unable to create or open shmem flink {} : {}", + shmem_flink, + err + ); + } + } +} + +fn set_all_perm(p: &str) { + #[cfg(not(windows))] + { + use std::os::unix::fs::PermissionsExt; + std::fs::set_permissions(p, std::fs::Permissions::from_mode(0o0777)).ok(); + } +} +*/