diff options
author | Martin Hurton <hurtonm@gmail.com> | 2010-02-12 12:12:49 +0100 |
---|---|---|
committer | Martin Hurton <hurtonm@gmail.com> | 2010-02-12 12:53:19 +0100 |
commit | cd7300fd4f25754f844b17a77685ec837ebecbbb (patch) | |
tree | 3c28cbb28e78ecb42c3b88fc46d6a034a5ae2065 | |
parent | 7f7ac843d58b3d8a77f681fa4c35bd21726b6f31 (diff) |
Resolve command starvation in recv()
-rw-r--r-- | src/socket_base.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/socket_base.cpp b/src/socket_base.cpp index 2eac84b..f5ba441 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -327,8 +327,23 @@ int zmq::socket_base_t::flush () int zmq::socket_base_t::recv (::zmq_msg_t *msg_, int flags_) { - // Get the message and return immediately if successfull. + // Get the message. int rc = xrecv (msg_, flags_); + + // Once every inbound_poll_rate messages check for signals and process + // incoming commands. This happens only if we are not polling altogether + // because there are messages available all the time. If poll occurs, + // ticks is set to zero and thus we avoid this code. + // + // Note that 'recv' uses different command throttling algorithm (the one + // described above) from the one used by 'send'. This is because counting + // ticks is more efficient than doing rdtsc all the time. + if (++ticks == inbound_poll_rate) { + app_thread->process_commands (false, false); + ticks = 0; + } + + // If we have the message, return immediately. if (rc == 0) return 0; @@ -346,27 +361,12 @@ int zmq::socket_base_t::recv (::zmq_msg_t *msg_, int flags_) } else { while (rc != 0) { - if (errno == EAGAIN) - app_thread->process_commands (true, false); - else + if (errno != EAGAIN) return -1; + app_thread->process_commands (true, false); rc = xrecv (msg_, flags_); + ticks = 0; } - ticks = 0; - } - - - // Once every inbound_poll_rate messages check for signals and process - // incoming commands. This happens only if we are not polling altogether - // because there are messages available all the time. If poll occurs, - // ticks is set to zero and thus we avoid this code. - // - // Note that 'recv' uses different command throttling algorithm (the one - // described above) from the one used by 'send'. This is because counting - // ticks is more efficient than doing rdtsc all the time. - if (++ticks == inbound_poll_rate) { - app_thread->process_commands (false, false); - ticks = 0; } return rc; |