Merge pull request #2029 from 21pages/stop-service
close all connections when stop service
This commit is contained in:
commit
fef5070db6
@ -288,7 +288,7 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
offstage: !svcStopped.value,
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
bool checked =
|
||||
bool checked = !bind.mainIsInstalled() ||
|
||||
await bind.mainCheckSuperUserPermission();
|
||||
if (checked) {
|
||||
bind.mainSetOption(key: "stop-service", value: "");
|
||||
|
@ -564,6 +564,7 @@ message Misc {
|
||||
bool restart_remote_device = 14;
|
||||
bool uac = 15;
|
||||
bool foreground_window_elevated = 16;
|
||||
bool stop_service = 17;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,8 @@ impl RendezvousMediator {
|
||||
}));
|
||||
}
|
||||
join_all(futs).await;
|
||||
} else {
|
||||
server.write().unwrap().close_connections();
|
||||
}
|
||||
sleep(1.).await;
|
||||
}
|
||||
|
@ -264,6 +264,17 @@ impl Server {
|
||||
self.connections.remove(&conn.id());
|
||||
}
|
||||
|
||||
pub fn close_connections(&mut self) {
|
||||
let conn_inners: Vec<_> = self.connections.values_mut().collect();
|
||||
for c in conn_inners {
|
||||
let mut misc = Misc::new();
|
||||
misc.set_stop_service(true);
|
||||
let mut msg = Message::new();
|
||||
msg.set_misc(misc);
|
||||
c.send(Arc::new(msg));
|
||||
}
|
||||
}
|
||||
|
||||
fn add_service(&mut self, service: Box<dyn Service>) {
|
||||
let name = service.name();
|
||||
self.services.insert(name, service);
|
||||
|
@ -250,14 +250,7 @@ impl Connection {
|
||||
}
|
||||
}
|
||||
ipc::Data::Close => {
|
||||
conn.close_manually = true;
|
||||
let mut misc = Misc::new();
|
||||
misc.set_close_reason("Closed manually by the peer".into());
|
||||
let mut msg_out = Message::new();
|
||||
msg_out.set_misc(misc);
|
||||
conn.send(msg_out).await;
|
||||
conn.on_close("Close requested from connection manager", false).await;
|
||||
SESSIONS.lock().unwrap().remove(&conn.lr.my_id);
|
||||
conn.on_close_manually("connection manager").await;
|
||||
break;
|
||||
}
|
||||
ipc::Data::ChatMessage{text} => {
|
||||
@ -404,6 +397,18 @@ impl Connection {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
match &msg.union {
|
||||
Some(message::Union::Misc(m)) => {
|
||||
match &m.union {
|
||||
Some(misc::Union::StopService(_)) => {
|
||||
conn.on_close_manually("stop service").await;
|
||||
break;
|
||||
}
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if let Err(err) = conn.stream.send(msg).await {
|
||||
conn.on_close(&err.to_string(), false).await;
|
||||
break;
|
||||
@ -1490,6 +1495,18 @@ impl Connection {
|
||||
self.port_forward_socket.take();
|
||||
}
|
||||
|
||||
async fn on_close_manually(&mut self, close_from: &str) {
|
||||
self.close_manually = true;
|
||||
let mut misc = Misc::new();
|
||||
misc.set_close_reason("Closed manually by the peer".into());
|
||||
let mut msg_out = Message::new();
|
||||
msg_out.set_misc(misc);
|
||||
self.send(msg_out).await;
|
||||
self.on_close(&format!("Close requested from {}", close_from), false)
|
||||
.await;
|
||||
SESSIONS.lock().unwrap().remove(&self.lr.my_id);
|
||||
}
|
||||
|
||||
fn read_dir(&mut self, dir: &str, include_hidden: bool) {
|
||||
let dir = dir.to_string();
|
||||
self.send_fs(ipc::FS::ReadDir {
|
||||
|
Loading…
x
Reference in New Issue
Block a user