Feature: Add support for publishing multiple buffers concatenated together #1736
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed in my previous PR (which I broke accidentally while force-pushing an unintended commit and subsequently closed that PR)
Motivation: If you want to make a single publish to consist of multiple buffers concatenated together, then instead of concatenating the buffers on the user's end and then passing it to
mosquitto_publish
the user can callmosquitto_publish_bufs
, which will reducememcpy
calls on the user's end.Example - If the user has 10 buffers each 20 bytes big, then the user will save cost (in terms of both, time and memory) of doing
memcpy
for a total of 200 bytes.Signature of the function:
int mosquitto_publish_bufs(mosq, mid, topic, buffers, buffers_cnt, qos, retain)
, wherebuffers
is an array of structbuf
, where^Taking into account the feedback provided on the last PR.
The difference in implementations for users will look like following:
With publish_bufs:
Without publish_bufs:
struct buf
instead of usingstruct iovec
(present in <sys/uio.h>) because of the feedback provided here of keeping the mosquitto API as consistent as possible across platforms.mosquitto_publish
a special case ofmosquitto_publish_bufs
to reduce code-duplication. I can make the two separate in-case the maintainer prefers so.buffers_cnt != 1
) and the currently present (03-publish-*) tests still pass confirming thatmosquitto_publish_bufs
works fine whenbuffers_cnt == 1
.make test
with your changes locally?