Skip to content
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

Problem: can no longer send user data from XSUB to XPUB #3659

Merged
merged 1 commit into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/xpub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,10 @@ void zmq::xpub_t::xread_activated (pipe_t *pipe_)
data = static_cast<unsigned char *> (sub.command_body ());
size = sub.command_body_size ();
subscribe = sub.is_subscribe ();
} else if (sub.size () > 0) {
unsigned char first = *msg_data;
if (first == 0 || first == 1) {
data = msg_data + 1;
size = sub.size () - 1;
subscribe = first == 1;
}
} else if (sub.size () > 0 && (*msg_data == 0 || *msg_data == 1)) {
data = msg_data + 1;
size = sub.size () - 1;
subscribe = *msg_data == 1;
} else {
// Process user message coming upstream from xsub socket
_pending_data.push_back (blob_t (msg_data, sub.size ()));
Expand Down
23 changes: 23 additions & 0 deletions tests/test_xpub_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,28 @@ void test_unsubscribe_cleanup ()
test_context_socket_close (sub);
}

void test_user_message ()
{
// Create a publisher
void *pub = test_context_socket (ZMQ_XPUB);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub, "inproc://soname"));

// Create a subscriber
void *sub = test_context_socket (ZMQ_XSUB);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, "inproc://soname"));

// Send some data that is neither sub nor unsub
const char subscription[] = {2, 'A', 0};
send_string_expect_success (sub, subscription, 0);

// Receive subscriptions from subscriber
recv_string_expect_success (pub, subscription, 0);

// Clean up.
test_context_socket_close (pub);
test_context_socket_close (sub);
}

int main ()
{
setup_test_environment ();
Expand All @@ -444,6 +466,7 @@ int main ()
RUN_TEST (test_xpub_proxy_unsubscribe_on_disconnect);
RUN_TEST (test_missing_subscriptions);
RUN_TEST (test_unsubscribe_cleanup);
RUN_TEST (test_user_message);

return UNITY_END ();
}