Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose EventLoop::clean #741

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rumqttc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Expose `EventLoop::clean` to allow triggering shutdown and subsequent storage of pending requests

### Changed

Expand Down
15 changes: 7 additions & 8 deletions rumqttc/src/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,15 @@ impl EventLoop {
}
}

fn clean(&mut self) {
/// Last session might contain packets which aren't acked. MQTT says these packets should be
/// republished in the next session. Move pending messages from state to eventloop, drops the
/// underlying network connection and clears the keepalive timeout if any.
///
/// NOTE: Use only when EventLoop is blocked on network and unable to immediately handle disconnect
pub fn clean(&mut self) {
self.network = None;
self.keepalive_timeout = None;
let pending = self.state.clean();
self.pending = pending.into_iter();
self.pending = self.state.clean().into_iter();
}

/// Yields Next notification or outgoing request and periodically pings
Expand Down Expand Up @@ -289,11 +293,6 @@ async fn connect(
// make MQTT connection request (which internally awaits for ack)
let packet = mqtt_connect(mqtt_options, &mut network).await?;

// Last session might contain packets which aren't acked. MQTT says these packets should be
// republished in the next session
// move pending messages from state to eventloop
// let pending = self.state.clean();
// self.pending = pending.into_iter();
Ok((network, packet))
}

Expand Down
10 changes: 7 additions & 3 deletions rumqttc/src/v5/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ impl EventLoop {
}
}

fn clean(&mut self) {
/// Last session might contain packets which aren't acked. MQTT says these packets should be
/// republished in the next session. Move pending messages from state to eventloop, drops the
/// underlying network connection and clears the keepalive timeout if any.
///
/// NOTE: Use only when EventLoop is blocked on network and unable to immediately handle disconnect
pub fn clean(&mut self) {
self.network = None;
self.keepalive_timeout = None;
let pending = self.state.clean();
self.pending = pending.into_iter();
self.pending = self.state.clean().into_iter();
}

/// Yields Next notification or outgoing request and periodically pings
Expand Down