From c636147c988a9c489b8463e86019f45651dd84af Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 28 Sep 2016 16:57:05 +0200 Subject: [PATCH] avoid duplicate entries in zmq_poll zmq_poller doesn't allow a socket to appear twice --- src/proxy.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/proxy.cpp b/src/proxy.cpp index 8c626af8..7161acea 100644 --- a/src/proxy.cpp +++ b/src/proxy.cpp @@ -130,6 +130,15 @@ int zmq::proxy ( { backend_, 0, ZMQ_POLLOUT, 0 } }; + int control_idx = 2; + if (frontend_ == backend_) { + // when frontend & backend are the same, + // avoid duplicate poll entries + qt_poll_items -= 1; + items[1] = items[2]; + control_idx = 1; + } + // Proxy can be in these three states enum { active, @@ -154,7 +163,7 @@ int zmq::proxy ( } // Process a control command if any - if (control_ && items [2].revents & ZMQ_POLLIN) { + if (control_ && items [control_idx].revents & ZMQ_POLLIN) { rc = control_->recv (&msg, 0); if (unlikely (rc < 0)) return -1;