-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Dynamic packet size #282
Dynamic packet size #282
Conversation
Hi, thanks for this. It is, on face value, a reasonable change. It's just needs me to have sufficient spare time to review in detail and go through the process of merging and releasing etc. Can't give you an outlook for that right now. |
All understood.
Let me know if i can be of any assistance.
thanks,
dunk.
…On Thu, May 4, 2017 at 2:06 PM, knolleary ***@***.***> wrote:
Hi, thanks for this. It is, on face value, a reasonable change. It's just
needs me to have sufficient spare time to review in detail and go through
the process of merging and releasing etc. Can't give you an outlook for
that right now.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#282 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEzU8mWigKZxukuD3_bSeP5o0OqKzYalks5r2c06gaJpZM4NMh-Y>
.
|
+1, also interested in dynamic packet size |
Any news on this? Right now when using this library have to tell everyone to download a forked copy or hack the existing define in their library folder... |
No news - will try to get to it in the next week. |
+1, more than interested in dynamic packet size. Thx |
+1 |
Interested as well. Thanks |
+1 Interested as well. Thanks |
yep +1 here, seems like some of my messages get lost if they are bigger than 128 bytes |
+1 Please merge this! It's a completely unnecessary burden to ask people to adjust a compile-time setting to build a library when it's got a dependency on this library. Looking at the code it seems completely backward compatible. |
Definitely interested in this. Thanks for the PR! |
do i have to pull this code manually into my cloned repo.. not seeing this in the master branch |
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.
This was done in a hurry so there may be other comments.
@@ -12,93 +12,125 @@ PubSubClient::PubSubClient() { | |||
this->_client = NULL; | |||
this->stream = NULL; | |||
setCallback(NULL); | |||
this->buffer_size = MQTT_MAX_PACKET_SIZE; |
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.
Woudn't it be better to move the buffer allocation to a support function, rather than duplicate the same code in all constructors?
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.
i agree in principal but
i was trying to match the existing code style. (ie, explicitly calling everything in each constructor.)
@knolleary any opinion?
} | ||
|
||
PubSubClient::~PubSubClient() { | ||
free(this->buffer); |
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.
This should check if this->buffer is NULL or not since setBufferSize() can set it to NULL.
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.
Nope. according to the spec std::free() should treat a null pointer as a no-op.
from http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf :
The free function causes the space pointed to by ptr to be deallocated, that is, made available for further allocation. If ptr is a null pointer, no action occurs.
(it makes sense because std::malloc returns null pointer on failure.)
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.
Ah, sweet, I haven't really coded C/C++ in ages and back then it was a no-no since freeing a null pointer would cause some environments to go belly up. :-)
@@ -586,3 +618,13 @@ PubSubClient& PubSubClient::setStream(Stream& stream){ | |||
int PubSubClient::state() { | |||
return this->_state; | |||
} | |||
|
|||
boolean PubSubClient::setBufferSize(uint16_t size) { | |||
this->buffer = (uint8_t*)realloc(this->buffer, size); |
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.
This should use a temp variable. If realloc fails it will return a NULL pointer without freeing the original memory. Thus, if NULL is returned this method should not make any change to this->buffer since it is still valid.
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. this makes sense.
@knolleary is this pull request likely to ever be merged? is it worth me doing this?
@@ -242,6 +279,7 @@ int main() | |||
test_receive_stream(); | |||
test_receive_max_sized_message(); | |||
test_receive_oversized_message(); | |||
test_resize_buffer(); |
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.
Since the merge request contains functionality to dynamically change the buffer size it would be suitable to have tests that verify that this works well. E g:
- What happens if setBufferSize() fails to allocate the memory?
- If the buffer size is shrunk will it fail (appropriately) to receive a message that was within the prior limits?
- And the reverse, if it fails to receive a message due to size will increasing the buffer size accordingly help?
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, all make sense. Let's see if this is likely to be merged first.
I'm curious if this is going to be merged? My project (http://github.com/ThisSmartHouse/CoogleIOT) relies on PubSubClient for it's MQTT and the lengthy topics the framework uses causes problems (specifically with my heartbeats of devices). Obviously we can side-step this issue with a compile-time flag but what can we do to actually get this dynamic allocation code into the library proper? |
+1 |
heavy plus for this feature (as well as for other similar configuration stuff)!.. forcing people to direct sources' modification means additional maintenance effort delegation to client code... so instead of just clicking "install" in a library manager to retrieve a new version, people have to keep an up to date overridden sources in their own libraries or frameworks... that might be quite disappointing... don't you think so?.. but anyway thanks for the great lib!.. |
Any news on this? |
At this point I don't understand why it hasn't been merged, other than the owner of the project just doesn't want to do it 👎 |
I agree this is a long overdue feature. The challenge has always been finding the time and energy to do the work needed to accept a change like this - especially as it's a feature I have little personal need for. I've also been fairly preoccupied with one of my other OSS projects... That said, I have recently started dusting off my hardware so I can test some of the proposed enhancements to the library. This one is high on the list... in fact, I may well have a play with it this evening... |
What do you make to this possible alternative > Appreciate any comments |
Well, it took me 3 years, but we got there eventually. Thanks for your patience @mrdunk. |
Cool, Thanks, AatVerzonden vanaf mijn mobiele telefoon-------- Oorspronkelijk bericht --------Onderwerp: Re: [knolleary/pubsubclient] Dynamic packet size (#282)Van: knolleary Aan: knolleary/pubsubclient Cc: Aat0304 ,Comment
Merged #282 into master.
—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or unsubscribe.
|
* Automatically set mqtt buffer size Current versions of pubsubclient allows the buffer size to be set dynamically: knolleary/pubsubclient#282 We can take advantage of this to avoid having to modify one of the dependencies and instead automatically up the buffer size when a powerful board is detected.
oh cool, just saw this made it in. |
Allow dynamic allocation of buffer size so rebuilding library is not required if user needs greater than MQTT_MAX_PACKET_SIZE (128) byte packet size.
See discussion at #110