-
Notifications
You must be signed in to change notification settings - Fork 102
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
AsyncClient::subscribe_many_with_options
loses options if there is only one filter
#120
Comments
Oh, damn, sorry. I fixed this in the C++ library a looooong time ago, but keep forgetting to fix it here as well. If I recall, the attitude for the C lib was to avoid the extra malloc when there's only one response. So this is considered a feature/optimization on their side; not a problem. So it won't be "fixed" there. I'll have a look at the PR shortly. |
Oooh... wait. This is not the issue I was thinking of! (I was remembering the problem in the callback when there's just a single response... there's no array of values and I was segfaulting on the NULL pointer). OK. I see it now. |
Yeah, the other one was in #51 :v |
So, you're saying that API is set in stone? |
Well the choice is left up to the app. If it knows that wants to subscribe to one topic, then the single |
I don't understand so many things about that design.
MQTTSubscribe_options subscribeOptions;
int subscribeOptionsCount;
MQTTSubscribe_options* subscribeOptionsList; ? They were doing spectacularly well, thriving even, with
sub->command.details.sub.topics = malloc(sizeof(char*) * count);
sub->command.details.sub.qoss = malloc(sizeof(int) * count); if we assume the mallocs are optimized together/away, it would be better to put the
I understand subscription calls are not a bottleneck and never will, but that optimization that impacts the API (and hotter calls like publish, with slightly larger Disclaimer: I don't understand C or performance. |
Yeah, if you look through issues/emails going back through the history of the C lib, you'll see me questioning and arguing about design decisions. Some is legacy (remembering that the library is probably like 15yo). But keep in mind... for the last 8ys that I've been tracking it, they have continued to to add to the library a crazy number of features, including full MQTT v5 support... without breaking the API once. That's pretty impressive. But I do keep thinking that it's time for a v2 that cleans up a lot of the weirdness. It's just that no one has the time or funding to do it. |
Due to the following code in the C library, which IMHO is questionable:
(found at https://github.com/eclipse/paho.mqtt.c/blob/64a5ff3c3b71fe019353aeacaebc66a3cf4f3461/src/MQTTAsync.c#L1029-L1048)
when passed in count is
count
is 1 (or 0 lol?) onlyopts
is written in, notoptlist
.Since only
ResponseOptionsBuilder::subscribe_many_options
and notResponseOptionsBuilder::subscribe_options
is called inAsyncClient::subscribe_many_with_options
,opts
remains at the default value, and that's what makes it into the packet.While I think this should be fixed in the C library, by differentiating into more concrete functions (and structs for their arguments), we can guard against it by additionally setting
opts
to the only option byte when the count is 1.(We should still set
optlist
in case this behavior improves, and a change in the C library API would require/suggest modifying these functions anyway, which is when this hacky accommodation can be removed)The text was updated successfully, but these errors were encountered: