Skip to content

Commit

Permalink
fix(liveman): noset conf net4mqtt error
Browse files Browse the repository at this point in the history
  • Loading branch information
a-wing committed Oct 7, 2024
1 parent eaf1c86 commit 86bbe39
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions liveman/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ where

#[cfg(feature = "net4mqtt")]
{
let (sender, mut receiver) = tokio::sync::mpsc::channel::<(String, String, Vec<u8>)>(10);

if let Some(c) = cfg.net4mqtt.clone() {
let (sender, mut receiver) = tokio::sync::mpsc::channel::<(String, String, Vec<u8>)>(10);

std::thread::spawn(move || {
tokio::runtime::Runtime::new()
.unwrap()
Expand All @@ -105,37 +105,37 @@ where
.unwrap()
});
});
}

std::thread::spawn(move || {
let dns = net4mqtt::kxdns::Kxdns::new(net4mqtt_domain);
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async move {
loop {
match receiver.recv().await {
Some((agent_id, _local_id, data)) => {
if data.len() > 5 {
nodes.write().unwrap().insert(
agent_id.clone(),
Node::new(
"".to_string(),
NodeKind::Net4mqtt,
format!("http://{}", dns.registry(&agent_id)),
),
);
} else {
nodes.write().unwrap().remove(&agent_id);
std::thread::spawn(move || {
let dns = net4mqtt::kxdns::Kxdns::new(net4mqtt_domain);
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async move {
loop {
match receiver.recv().await {
Some((agent_id, _local_id, data)) => {
if data.len() > 5 {
nodes.write().unwrap().insert(
agent_id.clone(),
Node::new(
"".to_string(),
NodeKind::Net4mqtt,
format!("http://{}", dns.registry(&agent_id)),
),
);
} else {
nodes.write().unwrap().remove(&agent_id);
}
}
None => {
error!("net4mqtt discovery receiver channel closed");
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
}
}
None => {
error!("net4mqtt discovery receiver channel closed");
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
}
}
}
})
});
})
});
}
}

let app_state = AppState {
Expand Down

0 comments on commit 86bbe39

Please sign in to comment.