just disable Ctrl+C graceful shutdown in the GUI for now
parent
41d5b896a9
commit
04975ee6c0
|
@ -12,8 +12,14 @@ use fltk::{
|
|||
|
||||
use tokio::{
|
||||
sync::Mutex,
|
||||
sync::oneshot,
|
||||
};
|
||||
|
||||
struct ServerInstance {
|
||||
task: tokio::task::JoinHandle <()>,
|
||||
shutdown_tx: oneshot::Sender <()>,
|
||||
}
|
||||
|
||||
fn main ()
|
||||
{
|
||||
let rt = tokio::runtime::Runtime::new ().unwrap ();
|
||||
|
@ -24,9 +30,9 @@ fn main ()
|
|||
let stopped_msg = "PTTH server: Stopped";
|
||||
let started_msg = "PTTH server: Running";
|
||||
|
||||
let ptth_server_task = Arc::new (Mutex::new (None));
|
||||
let server_instance = Arc::new (Mutex::new (None));
|
||||
|
||||
let shutdown_rx = ptth_core::graceful_shutdown::init ();
|
||||
// let shutdown_rx = ptth_core::graceful_shutdown::init ();
|
||||
|
||||
let app = app::App::default();
|
||||
let mut wind = Window::new(100, 100, 400, 300, "Hello from rust");
|
||||
|
@ -37,14 +43,16 @@ fn main ()
|
|||
wind.show();
|
||||
|
||||
{
|
||||
let ptth_server_task = Arc::clone (&ptth_server_task);
|
||||
let server_instance = Arc::clone (&server_instance);
|
||||
let mut frame = frame.clone ();
|
||||
let rt_handle = rt_handle.clone ();
|
||||
|
||||
but_run.set_callback (move |_| {
|
||||
rt_handle.block_on (async {
|
||||
let mut task = ptth_server_task.lock ().await;
|
||||
task.replace (Some (tokio::spawn (async {
|
||||
let mut server_instance = server_instance.lock ().await;
|
||||
let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel ();
|
||||
|
||||
let task = tokio::spawn (async {
|
||||
let config_file = ptth_server::ConfigFile {
|
||||
name: "ptth_server".into (),
|
||||
api_key: ptth_core::gen_key (),
|
||||
|
@ -53,8 +61,6 @@ fn main ()
|
|||
throttle_upload: false,
|
||||
};
|
||||
|
||||
let (_tx, shutdown_rx) = tokio::sync::oneshot::channel ();
|
||||
|
||||
if let Err (e) = ptth_server::run_server (
|
||||
config_file,
|
||||
shutdown_rx,
|
||||
|
@ -64,7 +70,12 @@ fn main ()
|
|||
{
|
||||
tracing::error! ("ptth_server crashed: {}", e);
|
||||
}
|
||||
})));
|
||||
});
|
||||
|
||||
server_instance.replace (Some (ServerInstance {
|
||||
task,
|
||||
shutdown_tx,
|
||||
}));
|
||||
});
|
||||
|
||||
frame.set_label (started_msg);
|
||||
|
@ -72,14 +83,14 @@ fn main ()
|
|||
}
|
||||
|
||||
{
|
||||
let ptth_server_task = Arc::clone (&ptth_server_task);
|
||||
let server_instance = Arc::clone (&server_instance);
|
||||
let mut frame = frame.clone ();
|
||||
let rt_handle = rt_handle.clone ();
|
||||
|
||||
but_stop.set_callback (move |_| {
|
||||
rt_handle.block_on (async {
|
||||
let mut task = ptth_server_task.lock ().await;
|
||||
task.replace (None);
|
||||
let mut server_instance = server_instance.lock ().await;
|
||||
server_instance.replace (None);
|
||||
});
|
||||
|
||||
frame.set_label (stopped_msg);
|
||||
|
|
Loading…
Reference in New Issue