diff options
| author | Arne Dußin | 2021-02-04 14:15:20 +0100 |
|---|---|---|
| committer | Arne Dußin | 2021-02-04 14:15:20 +0100 |
| commit | c0f8c067f6226981dc657a5a13fe0c0c5b0734d9 (patch) | |
| tree | a3f5aa2eedb6fa3215e05d582a51855ee6563402 /src/client_main.rs | |
| parent | 5652a771352ca0c9c344cd8d28dab291e8c415dc (diff) | |
| download | graf_karto-c0f8c067f6226981dc657a5a13fe0c0c5b0734d9.tar.gz graf_karto-c0f8c067f6226981dc657a5a13fe0c0c5b0734d9.zip | |
Make the server started by the client shut down
Before, the server thread would just continue running, after the window
had been closed. This is fixed now, with the server thread being
controlled by an atomic bool.
Diffstat (limited to 'src/client_main.rs')
| -rw-r--r-- | src/client_main.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/client_main.rs b/src/client_main.rs index 70dd857..43660d7 100644 --- a/src/client_main.rs +++ b/src/client_main.rs @@ -32,6 +32,7 @@ pub mod world; use clap::{App, Arg}; use server::DEFAULT_PORT; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, ToSocketAddrs}; +use std::sync::atomic::Ordering; fn main() { pretty_env_logger::init(); @@ -72,10 +73,10 @@ fn main() { let server_handle = if !matches.is_present("connect") { Some({ - let (server_handle, port) = + let (server_handle, server_running, port) = server::start_any_port(use_ipv4).expect("Unable to start local server"); server_port = port; - server_handle + (server_handle, server_running) }) } else { None @@ -111,7 +112,8 @@ fn main() { client::run(dbg!(server_address)); - if let Some(handle) = server_handle { + if let Some((handle, running)) = server_handle { + running.store(false, Ordering::Relaxed); handle.join().expect("Server thread closed unexpectedly."); } } |
