From 6b00f40f747fa3158f5d5d2eb7eef817c339a653 Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Fri, 11 Sep 2015 17:07:50 -0400 Subject: [PATCH] Problem: test_client/server_drop_more are invalid These tests connected CLIENT and SERVER to DEALER... this isn't allowed. I changed to CLIENT-to-SERVER in both cases. The result was aborts in client.cpp and server.cpp which cannot handle invalid multipart data. I removed the asserts in each of these in xsend. Solution: fix the test cases and remove the (unwanted?) asserts in client.cpp:xsend and server.cpp:xsend. --- src/client.cpp | 16 +++++----- src/server.cpp | 2 -- tests/test_client_drop_more.cpp | 52 ++++++++++++++++----------------- tests/test_server_drop_more.cpp | 28 +++++++++--------- 4 files changed, 45 insertions(+), 53 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index c8cd61fd..fccbfd9b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -46,7 +46,7 @@ void zmq::client_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) { LIBZMQ_UNUSED (subscribe_to_all_); - zmq_assert (pipe_); + zmq_assert (pipe_); fq.attach (pipe_); lb.attach (pipe_); @@ -54,28 +54,26 @@ void zmq::client_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) int zmq::client_t::xsend (msg_t *msg_) { - zmq_assert(!(msg_->flags () & msg_t::more)); - return lb.sendpipe (msg_, NULL); } int zmq::client_t::xrecv (msg_t *msg_) -{ +{ int rc = fq.recvpipe (msg_, NULL); // Drop any messages with more flag while (rc == 0 && msg_->flags () & msg_t::more) { // drop all frames of the current multi-frame message - rc = fq.recvpipe (msg_, NULL); - + rc = fq.recvpipe (msg_, NULL); + while (rc == 0 && msg_->flags () & msg_t::more) - rc = fq.recvpipe (msg_, NULL); + rc = fq.recvpipe (msg_, NULL); // get the new message - if (rc == 0) + if (rc == 0) rc = fq.recvpipe (msg_, NULL); - } + } return rc; } diff --git a/src/server.cpp b/src/server.cpp index 92cfb967..444e6dbf 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -93,8 +93,6 @@ void zmq::server_t::xwrite_activated (pipe_t *pipe_) int zmq::server_t::xsend (msg_t *msg_) { - zmq_assert(!(msg_->flags () & msg_t::more)); - // Find the pipe associated with the routing stored in the message. uint32_t routing_id = msg_->get_routing_id (); outpipes_t::iterator it = outpipes.find (routing_id); diff --git a/tests/test_client_drop_more.cpp b/tests/test_client_drop_more.cpp index 745f24eb..1a38ebec 100644 --- a/tests/test_client_drop_more.cpp +++ b/tests/test_client_drop_more.cpp @@ -29,7 +29,7 @@ #include "testutil.hpp" -int send_msg(zmq_msg_t* msg, void* s, int flags, int value); +int send_msg (zmq_msg_t* msg, void* s, int flags, int value); int main (void) { @@ -38,14 +38,14 @@ int main (void) assert (ctx); void *client = zmq_socket (ctx, ZMQ_CLIENT); - void *dealer = zmq_socket (ctx, ZMQ_DEALER); + void *server = zmq_socket (ctx, ZMQ_SERVER); int rc; rc = zmq_bind (client, "inproc://serverdropmore"); assert (rc == 0); - rc = zmq_connect (dealer, "inproc://serverdropmore"); + rc = zmq_connect (server, "inproc://serverdropmore"); assert (rc == 0); zmq_msg_t msg; @@ -53,34 +53,34 @@ int main (void) assert (rc == 0); // we will send 2 3-frames messages and then single frame message, only last one should be received - rc = send_msg (&msg, dealer, ZMQ_SNDMORE, 1); + rc = send_msg (&msg, client, ZMQ_SNDMORE, 1); assert(rc == 1); - rc = send_msg (&msg, dealer, ZMQ_SNDMORE, 2); + rc = send_msg (&msg, client, ZMQ_SNDMORE, 2); assert(rc == 1); - rc = send_msg (&msg, dealer, 0, 3); - assert(rc == 1); - - rc = send_msg (&msg, dealer, ZMQ_SNDMORE, 4); + rc = send_msg (&msg, client, 0, 3); assert(rc == 1); - rc = send_msg (&msg, dealer, ZMQ_SNDMORE, 5); - assert(rc == 1); - - rc = send_msg (&msg, dealer, 0, 6); + rc = send_msg (&msg, client, ZMQ_SNDMORE, 4); assert(rc == 1); - rc = send_msg (&msg, dealer, 0, 7); + rc = send_msg (&msg, client, ZMQ_SNDMORE, 5); assert(rc == 1); - rc = zmq_msg_recv (&msg, client, 0); - assert (rc == 1); + rc = send_msg (&msg, client, 0, 6); + assert(rc == 1); - assert(zmq_msg_more(&msg) == 0); + rc = send_msg (&msg, client, 0, 7); + assert(rc == 1); - unsigned char* data = (unsigned char*)zmq_msg_data (&msg); - assert (data[0] == 7); + rc = zmq_msg_recv (&msg, server, 0); + assert (rc == 1); + + assert (zmq_msg_more (&msg) == 0); + + unsigned char *data = (unsigned char*) zmq_msg_data (&msg); + assert (data [0] == 7); rc = zmq_msg_close (&msg); assert (rc == 0); @@ -88,7 +88,7 @@ int main (void) rc = zmq_close (client); assert (rc == 0); - rc = zmq_close (dealer); + rc = zmq_close (server); assert (rc == 0); rc = zmq_ctx_term (ctx); @@ -97,20 +97,18 @@ int main (void) return 0 ; } -int send_msg(zmq_msg_t* msg, void* s, int flags, int value) +int send_msg (zmq_msg_t *msg, void *s, int flags, int value) { - int rc = zmq_msg_close(msg); - + int rc = zmq_msg_close (msg); if (rc != 0) return rc; - zmq_msg_init_size(msg, 1); - + zmq_msg_init_size (msg, 1); if (rc != 0) return rc; - unsigned char* data = (unsigned char*)zmq_msg_data(msg); - data[0] = (unsigned char)value; + unsigned char *data = (unsigned char *) zmq_msg_data (msg); + data [0] = (unsigned char) value; return zmq_msg_send (msg, s, flags); } diff --git a/tests/test_server_drop_more.cpp b/tests/test_server_drop_more.cpp index 03d6a37d..e39b4c37 100644 --- a/tests/test_server_drop_more.cpp +++ b/tests/test_server_drop_more.cpp @@ -29,7 +29,7 @@ #include "testutil.hpp" -int send_msg(zmq_msg_t* msg, void* s, int flags, int value); +int send_msg (zmq_msg_t* msg, void* s, int flags, int value); int main (void) { @@ -38,7 +38,7 @@ int main (void) assert (ctx); void *server = zmq_socket (ctx, ZMQ_SERVER); - void *client = zmq_socket (ctx, ZMQ_DEALER); + void *client = zmq_socket (ctx, ZMQ_CLIENT); int rc; @@ -61,13 +61,13 @@ int main (void) rc = send_msg (&msg, client, 0, 3); assert(rc == 1); - + rc = send_msg (&msg, client, ZMQ_SNDMORE, 4); assert(rc == 1); rc = send_msg (&msg, client, ZMQ_SNDMORE, 5); assert(rc == 1); - + rc = send_msg (&msg, client, 0, 6); assert(rc == 1); @@ -75,12 +75,12 @@ int main (void) assert(rc == 1); rc = zmq_msg_recv (&msg, server, 0); - assert (rc == 1); + assert (rc == 1); - assert(zmq_msg_more(&msg) == 0); + assert (zmq_msg_more (&msg) == 0); - unsigned char* data = (unsigned char*)zmq_msg_data (&msg); - assert (data[0] == 7); + unsigned char *data = (unsigned char*) zmq_msg_data (&msg); + assert (data [0] == 7); rc = zmq_msg_close (&msg); assert (rc == 0); @@ -97,20 +97,18 @@ int main (void) return 0 ; } -int send_msg(zmq_msg_t* msg, void* s, int flags, int value) +int send_msg (zmq_msg_t *msg, void *s, int flags, int value) { - int rc = zmq_msg_close(msg); - + int rc = zmq_msg_close (msg); if (rc != 0) return rc; - zmq_msg_init_size(msg, 1); - + zmq_msg_init_size (msg, 1); if (rc != 0) return rc; - unsigned char* data = (unsigned char*)zmq_msg_data(msg); - data[0] = (unsigned char)value; + unsigned char *data = (unsigned char *) zmq_msg_data (msg); + data [0] = (unsigned char) value; return zmq_msg_send (msg, s, flags); }