Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Bug concerining identity in XREQ socket fixed (issue 280)

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
  • Loading branch information...
commit 21bca4dbe48cffdaa1e1108600973559a3b880d2 1 parent 1c23970
sustrik sustrik authored

Showing 2 changed files with 30 additions and 2 deletions. Show diff stats Hide diff stats

  1. +24 2 src/xreq.cpp
  2. +6 0 src/xreq.hpp
26 src/xreq.cpp
@@ -24,7 +24,8 @@
24 24 #include "msg.hpp"
25 25
26 26 zmq::xreq_t::xreq_t (class ctx_t *parent_, uint32_t tid_) :
27   - socket_base_t (parent_, tid_)
  27 + socket_base_t (parent_, tid_),
  28 + prefetched (false)
28 29 {
29 30 options.type = ZMQ_XREQ;
30 31
@@ -36,10 +37,13 @@ zmq::xreq_t::xreq_t (class ctx_t *parent_, uint32_t tid_) :
36 37
37 38 options.send_identity = true;
38 39 options.recv_identity = true;
  40 +
  41 + prefetched_msg.init ();
39 42 }
40 43
41 44 zmq::xreq_t::~xreq_t ()
42 45 {
  46 + prefetched_msg.close ();
43 47 }
44 48
45 49 void zmq::xreq_t::xattach_pipe (pipe_t *pipe_)
@@ -56,6 +60,14 @@ int zmq::xreq_t::xsend (msg_t *msg_, int flags_)
56 60
57 61 int zmq::xreq_t::xrecv (msg_t *msg_, int flags_)
58 62 {
  63 + // If there is a prefetched message, return it.
  64 + if (prefetched) {
  65 + int rc = msg_->move (prefetched_msg);
  66 + errno_assert (rc == 0);
  67 + prefetched = false;
  68 + return 0;
  69 + }
  70 +
59 71 // XREQ socket doesn't use identities. We can safely drop it and
60 72 while (true) {
61 73 int rc = fq.recv (msg_, flags_);
@@ -69,7 +81,17 @@ int zmq::xreq_t::xrecv (msg_t *msg_, int flags_)
69 81
70 82 bool zmq::xreq_t::xhas_in ()
71 83 {
72   - return fq.has_in ();
  84 + // We may already have a message pre-fetched.
  85 + if (prefetched)
  86 + return true;
  87 +
  88 + // Try to read the next message to the pre-fetch buffer.
  89 + int rc = xrecv (&prefetched_msg, ZMQ_DONTWAIT);
  90 + if (rc != 0 && errno == EAGAIN)
  91 + return false;
  92 + zmq_assert (rc == 0);
  93 + prefetched = true;
  94 + return true;
73 95 }
74 96
75 97 bool zmq::xreq_t::xhas_out ()
6 src/xreq.hpp
@@ -62,6 +62,12 @@ namespace zmq
62 62 fq_t fq;
63 63 lb_t lb;
64 64
  65 + // Have we prefetched a message.
  66 + bool prefetched;
  67 +
  68 + // Holds the prefetched message.
  69 + msg_t prefetched_msg;
  70 +
65 71 xreq_t (const xreq_t&);
66 72 const xreq_t &operator = (const xreq_t&);
67 73 };

0 comments on commit 21bca4d

Please sign in to comment.
Something went wrong with that request. Please try again.