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

View File

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