Gracefully shutdown if SIGINT was sent in TUI mode (#2784)

Fixes #2799

Also 2 Arc's were replaced by one server's instance.
It is needed for p2p thread management in #2778, currently there is no point where we could store thread handles and join them because thread::join
consume the caller, which is impossible in case of Arc.
This commit is contained in:
hashmap
2019-05-03 14:20:36 +02:00
committed by GitHub
parent 85d06fe416
commit 55cbdf58fe
3 changed files with 15 additions and 38 deletions
+6 -11
View File
@@ -45,21 +45,16 @@ fn start_server_tui(config: servers::ServerConfig) {
// everything it might need
if config.run_tui.unwrap_or(false) {
warn!("Starting GRIN in UI mode...");
servers::Server::start(config, |serv: Arc<servers::Server>| {
let running = Arc::new(AtomicBool::new(true));
let _ = thread::Builder::new()
.name("ui".to_string())
.spawn(move || {
let mut controller = ui::Controller::new().unwrap_or_else(|e| {
panic!("Error loading UI controller: {}", e);
});
controller.run(serv.clone(), running);
});
servers::Server::start(config, |serv: servers::Server| {
let mut controller = ui::Controller::new().unwrap_or_else(|e| {
panic!("Error loading UI controller: {}", e);
});
controller.run(serv);
})
.unwrap();
} else {
warn!("Starting GRIN w/o UI...");
servers::Server::start(config, |serv: Arc<servers::Server>| {
servers::Server::start(config, |serv: servers::Server| {
let running = Arc::new(AtomicBool::new(true));
let r = running.clone();
ctrlc::set_handler(move || {