-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expose the ability to have zero allocation sends. #4802
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
Open
cptspacemanspiff
wants to merge
10
commits into
zeromq:master
Choose a base branch
from
cptspacemanspiff:no-allocation-sends
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
62440f3
Initial changes to the header file to support no-allocation sends.
c232158
cast the memory content to actual zmq type.
3b39139
duplicated ffn test.
dcbe56d
Added external storage test.
2c787a0
moved the new methods to draft
2d8c5e5
fixed draft symbols/ formatting / tests
2744358
formatting.
7cd1725
autotools tests
981d964
added more tests locations?
04d5656
Use typedef rathar than reimplementing the logic to define the 64byte…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* SPDX-License-Identifier: MPL-2.0 */ | ||
|
|
||
| #include "testutil.hpp" | ||
| #include "testutil_unity.hpp" | ||
|
|
||
| #include <string.h> | ||
|
|
||
| SETUP_TEARDOWN_TESTCONTEXT | ||
|
|
||
| void ffn (void *data_, void *hint_) | ||
| { | ||
| // Signal that ffn has been called by writing "freed" to hint | ||
| (void) data_; // Suppress 'unused' warnings at compile time | ||
| memcpy (hint_, (void *) "freed", 5); | ||
| } | ||
|
|
||
| void test_msg_init_ffn_external_storage () | ||
| { | ||
| // Create the infrastructure | ||
| char my_endpoint[MAX_SOCKET_STRING]; | ||
|
|
||
| void *router = test_context_socket (ZMQ_ROUTER); | ||
| bind_loopback_ipv4 (router, my_endpoint, sizeof my_endpoint); | ||
|
|
||
| void *dealer = test_context_socket (ZMQ_DEALER); | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (dealer, my_endpoint)); | ||
|
|
||
| // Test that creating and closing a message triggers ffn | ||
| zmq_msg_content_t *content = new zmq_msg_content_t; | ||
| zmq_msg_t msg; | ||
| char hint[5]; | ||
| char data[255]; | ||
| memset (data, 0, 255); | ||
| memcpy (data, (void *) "data", 4); | ||
| memcpy (hint, (void *) "hint", 4); | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_external_storage ( | ||
| &msg, content, (void *) data, 255, ffn, (void *) hint)); | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); | ||
|
|
||
| msleep (SETTLE_TIME); | ||
| TEST_ASSERT_EQUAL_STRING_LEN ("freed", hint, 5); | ||
| memcpy (hint, (void *) "hint", 4); | ||
|
|
||
| // Making and closing a copy triggers ffn | ||
| zmq_msg_t msg2; | ||
| zmq_msg_init (&msg2); | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_external_storage ( | ||
| &msg, content, (void *) data, 255, ffn, (void *) hint)); | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_copy (&msg2, &msg)); | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg2)); | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); | ||
|
|
||
| msleep (SETTLE_TIME); | ||
| TEST_ASSERT_EQUAL_STRING_LEN ("freed", hint, 5); | ||
| memcpy (hint, (void *) "hint", 4); | ||
|
|
||
| // Test that sending a message triggers ffn | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_external_storage ( | ||
| &msg, content, (void *) data, 255, ffn, (void *) hint)); | ||
|
|
||
| zmq_msg_send (&msg, dealer, 0); | ||
| char buf[255]; | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_recv (router, buf, 255, 0)); | ||
| TEST_ASSERT_EQUAL_INT (255, zmq_recv (router, buf, 255, 0)); | ||
| TEST_ASSERT_EQUAL_STRING_LEN (data, buf, 4); | ||
|
|
||
| msleep (SETTLE_TIME); | ||
| TEST_ASSERT_EQUAL_STRING_LEN ("freed", hint, 5); | ||
| memcpy (hint, (void *) "hint", 4); | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); | ||
|
|
||
| // Sending a copy of a message triggers ffn | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg2)); | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_external_storage ( | ||
| &msg, content, (void *) data, 255, ffn, (void *) hint)); | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_copy (&msg2, &msg)); | ||
|
|
||
| zmq_msg_send (&msg, dealer, 0); | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_recv (router, buf, 255, 0)); | ||
| TEST_ASSERT_EQUAL_INT (255, zmq_recv (router, buf, 255, 0)); | ||
| TEST_ASSERT_EQUAL_STRING_LEN (data, buf, 4); | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg2)); | ||
| TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); | ||
|
|
||
| msleep (SETTLE_TIME); | ||
| TEST_ASSERT_EQUAL_STRING_LEN ("freed", hint, 5); | ||
|
|
||
| // Deallocate the infrastructure. | ||
| test_context_socket_close (router); | ||
| test_context_socket_close (dealer); | ||
|
|
||
| delete content; | ||
| } | ||
|
|
||
| int main (void) | ||
| { | ||
| setup_test_environment (); | ||
|
|
||
| UNITY_BEGIN (); | ||
| RUN_TEST (test_msg_init_ffn_external_storage); | ||
| return UNITY_END (); | ||
| } |
Oops, something went wrong.
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.
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.
Why are you adding a new type that is identical to the existing one? Just reuse that?
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.
Hey @bluca Thanks a bunch for looking at this,
I just changed this for zmq_msg_content_t to be a typedef alias of the zmq_msg_t.
I wanted them to be different types because conceptually they are - They just happen to be the same size/alignment requirements but they are used differently internally. One is a block for a zeroMQ message to be built in while the other is for a control block. I did not want to get confused about what types were going where/ what they were being used for.
Hence the desire for at least differently named types (even if they are just aliases now)
(I tested the change on our code base, and there are no issues as one would expect - Though I am not sure about what is going on with the MacOS CI here...)