Stop and join all Electrum client threads on SIGINT

This commit is contained in:
Roman Zeyde 2018-06-14 00:07:35 +03:00
parent 165b48ccce
commit 284275e2d1
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB

View File

@ -421,19 +421,26 @@ impl RPC {
let senders = Arc::new(Mutex::new(Vec::<SyncSender<Message>>::new()));
let acceptor = RPC::start_acceptor(addr);
RPC::start_notifier(notification, senders.clone(), acceptor.sender());
let mut children = vec![];
while let Some((stream, addr)) = acceptor.receiver().recv().unwrap() {
let query = query.clone();
let senders = senders.clone();
let stats = stats.clone();
thread::spawn(move || {
children.push(thread::spawn(move || {
info!("[{}] connected peer", addr);
let conn = Connection::new(query, stream, addr, stats);
senders.lock().unwrap().push(conn.chan.sender());
conn.run();
info!("[{}] disconnected peer", addr);
});
}));
}
info!("stopping RPC server");
for sender in senders.lock().unwrap().iter() {
let _ = sender.send(Message::Done);
}
for child in children {
let _ = child.join();
}
info!("stopping RPC server")
}),
};
handle