From 0f10ef1b38afdecaaccf2b0c28501e55411c664f Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 5 Jun 2015 13:45:10 -0700 Subject: [PATCH 1/2] fix scope of itemsout poll indentation was correct, but poll was inside `if control`, causing it to only be called if there is a control message. This would cause proxy messages to only be delivered after a control message had been sent. --- src/proxy.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/proxy.cpp b/src/proxy.cpp index 0d2b6b16..c79aeff6 100644 --- a/src/proxy.cpp +++ b/src/proxy.cpp @@ -93,18 +93,18 @@ int zmq::proxy ( if (unlikely (rc < 0)) return -1; - // Process a control command if any - if (control_ && items [2].revents & ZMQ_POLLIN) { - rc = control_->recv (&msg, 0); - if (unlikely (rc < 0)) - return -1; - // Get the pollout separately because when combining this with pollin it maxes the CPU // because pollout shall most of the time return directly rc = zmq_poll (&itemsout [0], 2, 0); if (unlikely (rc < 0)) return -1; + // Process a control command if any + if (control_ && items [2].revents & ZMQ_POLLIN) { + rc = control_->recv (&msg, 0); + if (unlikely (rc < 0)) + return -1; + moresz = sizeof more; rc = control_->getsockopt (ZMQ_RCVMORE, &more, &moresz); if (unlikely (rc < 0) || more) From 286c6f93eed1487d1fc86ea1f8fdbdd6eb0a965d Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 5 Jun 2015 13:45:23 -0700 Subject: [PATCH 2/2] test that proxy messages are received --- tests/test_proxy_terminate.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_proxy_terminate.cpp b/tests/test_proxy_terminate.cpp index 83e70d4b..d6b08cf5 100644 --- a/tests/test_proxy_terminate.cpp +++ b/tests/test_proxy_terminate.cpp @@ -86,22 +86,41 @@ int main (void) rc = zmq_connect (publisher, "tcp://127.0.0.1:15564"); assert (rc == 0); + // Start a secondary puller which reads the data out the other end + char buf[255]; + void *puller = zmq_socket (ctx, ZMQ_PULL); + assert (puller); + rc = zmq_connect (puller, "tcp://127.0.0.1:15563"); + assert (rc == 0); + msleep (50); rc = zmq_send (publisher, "This is a test", 14, 0); assert (rc == 14); + rc = zmq_recv (puller, buf, 255, 0); + assert (rc == 14); + msleep (50); rc = zmq_send (publisher, "This is a test", 14, 0); assert (rc == 14); + rc = zmq_recv (puller, buf, 255, 0); + assert (rc == 14); + msleep (50); rc = zmq_send (publisher, "This is a test", 14, 0); assert (rc == 14); + + rc = zmq_recv (puller, buf, 255, 0); + assert (rc == 14); + rc = zmq_send (control, "TERMINATE", 9, 0); assert (rc == 9); rc = zmq_close (publisher); assert (rc == 0); + rc = zmq_close (puller); + assert (rc == 0); rc = zmq_close (control); assert (rc == 0);