diff --git a/src/proxy.cpp b/src/proxy.cpp index 73e3441a..0d2b6b16 100644 --- a/src/proxy.cpp +++ b/src/proxy.cpp @@ -71,12 +71,15 @@ int zmq::proxy ( int more; size_t moresz; zmq_pollitem_t items [] = { - { frontend_, 0, ZMQ_POLLIN | ZMQ_POLLOUT, 0 }, - { backend_, 0, ZMQ_POLLIN | ZMQ_POLLOUT, 0 }, + { frontend_, 0, ZMQ_POLLIN, 0 }, + { backend_, 0, ZMQ_POLLIN, 0 }, { control_, 0, ZMQ_POLLIN, 0 } }; int qt_poll_items = (control_ ? 3 : 2); - + zmq_pollitem_t itemsout [] = { + { frontend_, 0, ZMQ_POLLOUT, 0 }, + { backend_, 0, ZMQ_POLLOUT, 0 } + }; // Proxy can be in these three states enum { active, @@ -96,6 +99,12 @@ int zmq::proxy ( 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; + moresz = sizeof more; rc = control_->getsockopt (ZMQ_RCVMORE, &more, &moresz); if (unlikely (rc < 0) || more) @@ -132,7 +141,7 @@ int zmq::proxy ( // Process a request if (state == active && items [0].revents & ZMQ_POLLIN - && items [1].revents & ZMQ_POLLOUT) { + && itemsout [1].revents & ZMQ_POLLOUT) { while (true) { rc = frontend_->recv (&msg, 0); if (unlikely (rc < 0)) @@ -166,7 +175,7 @@ int zmq::proxy ( // Process a reply if (state == active && items [1].revents & ZMQ_POLLIN - && items [0].revents & ZMQ_POLLOUT) { + && itemsout [0].revents & ZMQ_POLLOUT) { while (true) { rc = backend_->recv (&msg, 0); if (unlikely (rc < 0))