-
Notifications
You must be signed in to change notification settings - Fork 200
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
Implement MQTT outbox limits and get_outbox_size() #560
Conversation
An outbox limit of 0 is the default and disables the limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable.The only question is if we should model the no_limit as 0 and not an Option as most other fields here, but i guess that's a nit. ( Assuming no limit is actually 0 and not something like u64::max :D )
Technically its a breaking change since we add a pub field to the struct but well its so minimal its fine from my site.
I actually prefer Also, I might very soon introduce 2 breaking changes, so breaking the API in a minor way probably not a big deal. |
Regarding Option vs 0: I thought about going this route but then tried to mimic the style of e.g. buf.out_size. (edit: with two comments about this already, I'm going for the Option variant) I added a Default::default for the outbox_config_t type as I was missing this. (edit: with option not useful anymore, only set what you have) Unfortunately I did not find any public documentation on the behavior of the default 0 but looked at sources: |
OK - thanks a lot! In general I need this too as well - in fact - ASAP - so this is arriving just in time. :) |
made it optional and moved it out of the explicit config to the part where the optional config fields are used |
btw, if you want me to move the change from the added to the breaking section, I can totally do this. I was just not if I should based on your comments |
src/mqtt/client.rs
Outdated
@@ -625,6 +631,10 @@ impl<'a> EspMqttClient<'a> { | |||
Self::check(unsafe { esp_mqtt_client_set_uri(self.raw_client, uri.as_ptr()) }) | |||
} | |||
|
|||
pub fn get_outbox_size(&self) -> i32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i32
here is a weird choice. ESP-IDF seems to cast the internal uint64_t
to i32
(weird?? why?). Regardless, we should instead return a usize
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm not sure if this was done by accident or on purpose but internally it is by default 0 and if available the uint64_t.
I gave it another try and capped the value at 0 and return it as usize. wdyt?
Thanks! |
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
cargo fmt
command to ensure that all changed code is formatted correctly.cargo clippy
command to ensure that all changed code passes latest Clippy nightly lints.CHANGELOG.md
in the proper section.Pull Request Details 📖
Description
This change implements get_outbox_size() on the EspMqttClient to retrieve the amount of bytes currently stored in the MQTT outbox.
Additionally implement a configurable option in MqttClientConfiguration to limit the outbox size to the given amount of bytes so there is no ever growing outbox size that might fill up the entire RAM.
Testing
I tested the limit with this configuration and sent a a lot of bytes
and tested it with
The message is shown if no limit is configured and does not show up once a limit of 5000 is set.
This returns
cannot enqueue mqtt message: ERROR
if the outbox is full.