Skip to content

Commit

Permalink
feat(rumqttc): set session_expiry_interval in v5 (#854)
Browse files Browse the repository at this point in the history
Co-authored-by: Devdutt Shenoi <devdutt@outlook.in>
  • Loading branch information
xiaocq2001 and de-sh committed May 16, 2024
1 parent 7f594f8 commit ce8422b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions rumqttc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `size()` method on `Packet` calculates size once serialized.
* `read()` and `write()` methods on `Packet`.
* `ConnectionAborted` variant on `StateError` type to denote abrupt end to a connection
* `set_session_expiry_interval` and `session_expiry_interval` methods on `MqttOptions`.

### Changed

Expand Down
1 change: 1 addition & 0 deletions rumqttc/examples/async_manual_acks_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fn create_conn() -> (AsyncClient, EventLoop) {
let mut mqttoptions = MqttOptions::new("test-1", "localhost", 1884);
mqttoptions
.set_keep_alive(Duration::from_secs(5))
.set_session_expiry_interval(u32::MAX.into())
.set_manual_acks(true)
.set_clean_start(false);

Expand Down
5 changes: 5 additions & 0 deletions rumqttc/src/v5/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ async fn mqtt_connect(
options.keep_alive = Duration::from_secs(keep_alive as u64);
}
network.set_max_outgoing_size(props.max_packet_size);

// Override local session_expiry_interval value if set by server.
if props.session_expiry_interval.is_some() {
options.set_session_expiry_interval(props.session_expiry_interval);
}
}
Ok(Packet::ConnAck(connack))
}
Expand Down
21 changes: 21 additions & 0 deletions rumqttc/src/v5/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,27 @@ impl MqttOptions {
self.connect_properties.clone()
}

/// set session expiry interval on connection properties
pub fn set_session_expiry_interval(&mut self, interval: Option<u32>) -> &mut Self {
if let Some(conn_props) = &mut self.connect_properties {
conn_props.session_expiry_interval = interval;
self
} else {
let mut conn_props = ConnectProperties::new();
conn_props.session_expiry_interval = interval;
self.set_connect_properties(conn_props)
}
}

/// get session expiry interval on connection properties
pub fn session_expiry_interval(&self) -> Option<u32> {
if let Some(conn_props) = &self.connect_properties {
conn_props.session_expiry_interval
} else {
None
}
}

/// set receive maximum on connection properties
pub fn set_receive_maximum(&mut self, recv_max: Option<u16>) -> &mut Self {
if let Some(conn_props) = &mut self.connect_properties {
Expand Down

0 comments on commit ce8422b

Please sign in to comment.