fix on should_exit

This commit is contained in:
open-trade 2022-02-08 18:09:45 +08:00
parent 6143a3c649
commit dddbae4eb1
2 changed files with 7 additions and 6 deletions

View File

@ -264,6 +264,7 @@ async fn handle(data: Data, stream: &mut Connection) {
{ {
RendezvousMediator::restart(); RendezvousMediator::restart();
} }
allow_err!(stream.send(&Data::Options(None)).await);
} }
}, },
Data::NatType(_) => { Data::NatType(_) => {
@ -497,11 +498,11 @@ pub fn set_option(key: &str, value: &str) {
#[tokio::main(flavor = "current_thread")] #[tokio::main(flavor = "current_thread")]
pub async fn set_options(value: HashMap<String, String>) -> ResultType<()> { pub async fn set_options(value: HashMap<String, String>) -> ResultType<()> {
Config::set_options(value.clone()); let mut c = connect(1000, "").await?;
connect(1000, "") c.send(&Data::Options(Some(value.clone()))).await?;
.await? // do not put below before connect, because we need to check should_exit
.send(&Data::Options(Some(value))) c.next_timeout(1000).await.ok();
.await?; Config::set_options(value);
Ok(()) Ok(())
} }

View File

@ -43,6 +43,7 @@ pub struct RendezvousMediator {
impl RendezvousMediator { impl RendezvousMediator {
pub fn restart() { pub fn restart() {
SHOULD_EXIT.store(true, Ordering::SeqCst); SHOULD_EXIT.store(true, Ordering::SeqCst);
log::info!("server restar");
} }
pub async fn start_all() { pub async fn start_all() {
@ -74,7 +75,6 @@ impl RendezvousMediator {
SHOULD_EXIT.store(false, Ordering::SeqCst); SHOULD_EXIT.store(false, Ordering::SeqCst);
for host in servers.clone() { for host in servers.clone() {
let server = server.clone(); let server = server.clone();
let servers = servers.clone();
futs.push(tokio::spawn(async move { futs.push(tokio::spawn(async move {
allow_err!(Self::start(server, host).await); allow_err!(Self::start(server, host).await);
// SHOULD_EXIT here is to ensure once one exits, the others also exit. // SHOULD_EXIT here is to ensure once one exits, the others also exit.