Skip to content

Commit

Permalink
fix: ordering of events as mentioned in #860
Browse files Browse the repository at this point in the history
  • Loading branch information
de-sh committed May 9, 2024
1 parent c5bfdd7 commit 8d6b372
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion rumqttc/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ impl MqttState {
&mut self,
packet: Incoming,
) -> Result<Option<Packet>, StateError> {
self.events.push_back(Event::Incoming(packet.clone()));

let outgoing = match &packet {
Incoming::PingResp => self.handle_incoming_pingresp()?,
Incoming::Publish(publish) => self.handle_incoming_publish(publish)?,
Expand All @@ -179,7 +181,6 @@ impl MqttState {
return Err(StateError::WrongPacket);
}
};
self.events.push_back(Event::Incoming(packet));
self.last_incoming = Instant::now();

Ok(outgoing)
Expand Down
5 changes: 3 additions & 2 deletions rumqttc/src/v5/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub enum StateError {
#[error("Connection failed with reason '{reason:?}' ")]
ConnFail { reason: ConnectReturnCode },
#[error("Connection closed by peer abruptly")]
ConnectionAborted
ConnectionAborted,
}

impl From<mqttbytes::Error> for StateError {
Expand Down Expand Up @@ -217,6 +217,8 @@ impl MqttState {
&mut self,
mut packet: Incoming,
) -> Result<Option<Packet>, StateError> {
self.events.push_back(Event::Incoming(packet.to_owned()));

let outgoing = match &mut packet {
Incoming::PingResp(_) => self.handle_incoming_pingresp()?,
Incoming::Publish(publish) => self.handle_incoming_publish(publish)?,
Expand All @@ -234,7 +236,6 @@ impl MqttState {
}
};

self.events.push_back(Event::Incoming(packet));
self.last_incoming = Instant::now();
Ok(outgoing)
}
Expand Down

0 comments on commit 8d6b372

Please sign in to comment.