lan discovery will be done soon

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2021-12-19 19:58:08 +08:00
parent bcbe9ccbe5
commit 5682b088de
11 changed files with 254 additions and 31 deletions

View File

@@ -86,6 +86,8 @@ pub fn start(args: &mut [String]) {
let childs: Childs = Default::default();
let cloned = childs.clone();
std::thread::spawn(move || check_zombie(cloned));
let cloned = childs.clone();
tokio::spawn(async move {start_ipc(cloned)});
crate::common::check_software_update();
frame.event_handler(UI::new(childs));
frame.sciter_handler(UIHostHandler {});
@@ -644,6 +646,55 @@ pub fn check_zombie(childs: Childs) {
}
}
// TODO: Duplicated code.
// Need more generic and better shutdown handler
#[tokio::main(flavor = "current_thread")]
async fn start_ipc(childs: Childs) {
match ipc::new_listener("_index").await {
Ok(mut incoming) => {
while let Some(result) = incoming.next().await {
match result {
Ok(stream) => {
let mut stream = ipc::Connection::new(stream);
let childs = childs.clone();
tokio::spawn(async move {
loop {
tokio::select! {
res = stream.next() => {
match res {
Err(err) => {
log::info!("cm ipc connection closed: {}", err);
break;
}
Ok(Some(data)) => {
match data {
ipc::Data::SessionsUpdated => {
childs.lock().unwrap().0 = true;
}
_ => {
}
}
}
_ => {}
}
}
}
}
});
}
Err(err) => {
log::error!("Couldn't get index client: {:?}", err);
}
}
}
}
Err(err) => {
log::error!("Failed to start index ipc server: {}", err);
}
}
std::process::exit(-1);
}
// notice: avoiding create ipc connection repeatedly,
// because windows named pipe has serious memory leak issue.
#[tokio::main(flavor = "current_thread")]