Skip to content

Commit

Permalink
fix(mqtt_history): startup connection until ConnAck
Browse files Browse the repository at this point in the history
check all until ConnAck, not just one
  • Loading branch information
EdJoPaTo committed Oct 30, 2020
1 parent ca2d304 commit 4e146e1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/mqtt_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ pub struct HistoryEntry {
pub type HistoryArc = Arc<Mutex<HashMap<String, Vec<HistoryEntry>>>>;

pub fn start(mut connection: Connection) -> Result<(HistoryArc, JoinHandle<()>), Box<dyn Error>> {
// TODO: weird workaround. Is there a better solution?
// Iterate once. This is the initial connection attempt. When this fails it still fails in the main thread which is less messy. Happens for example when the host is wrong.
connection.iter().next().unwrap()?;
// Iterate until there is a ConnAck. When this fails it still fails in the main thread which is less messy. Happens for example when the host is wrong.
for notification in connection.iter() {
if let rumqttc::Event::Incoming(packet) = notification.expect("connection error") {
if let rumqttc::Packet::ConnAck(_) = packet {
break;
}
}
}

let history = Arc::new(Mutex::new(HashMap::new()));

Expand Down

0 comments on commit 4e146e1

Please sign in to comment.