Problem: REQ socket with ZMQ_REQ_RELAXED does not report ZMQ_POLLOUT when queried for events after first message.

Solution: Check for strictness before returning false if no reply has been received.
This commit is contained in:
Rolf Timmermans
2017-11-08 09:55:14 +01:00
parent b3d19ffe1a
commit c8592dfbc3
2 changed files with 20 additions and 2 deletions

View File

@@ -213,7 +213,7 @@ bool zmq::req_t::xhas_in ()
bool zmq::req_t::xhas_out () bool zmq::req_t::xhas_out ()
{ {
if (receiving_reply) if (receiving_reply && strict)
return false; return false;
return dealer_t::xhas_out (); return dealer_t::xhas_out ();

View File

@@ -54,6 +54,16 @@ static void bounce (void *socket)
} while (more); } while (more);
} }
static int get_events (void *socket)
{
int rc;
int events;
size_t events_size = sizeof(events);
rc = zmq_getsockopt (socket, ZMQ_EVENTS, &events, &events_size);
assert (rc == 0);
return events;
}
int main (void) int main (void)
{ {
setup_test_environment (); setup_test_environment ();
@@ -97,14 +107,23 @@ int main (void)
// Case 1: Second send() before a reply arrives in a pipe. // Case 1: Second send() before a reply arrives in a pipe.
int events = get_events (req);
assert(events == ZMQ_POLLOUT);
// Send a request, ensure it arrives, don't send a reply // Send a request, ensure it arrives, don't send a reply
s_send_seq (req, "A", "B", SEQ_END); s_send_seq (req, "A", "B", SEQ_END);
s_recv_seq (rep [0], "A", "B", SEQ_END); s_recv_seq (rep [0], "A", "B", SEQ_END);
events = get_events (req);
assert(events == ZMQ_POLLOUT);
// Send another request on the REQ socket // Send another request on the REQ socket
s_send_seq (req, "C", "D", SEQ_END); s_send_seq (req, "C", "D", SEQ_END);
s_recv_seq (rep [1], "C", "D", SEQ_END); s_recv_seq (rep [1], "C", "D", SEQ_END);
events = get_events (req);
assert(events == ZMQ_POLLOUT);
// Send a reply to the first request - that should be discarded by the REQ // Send a reply to the first request - that should be discarded by the REQ
s_send_seq (rep [0], "WRONG", SEQ_END); s_send_seq (rep [0], "WRONG", SEQ_END);
@@ -112,7 +131,6 @@ int main (void)
s_send_seq (rep [1], "OK", SEQ_END); s_send_seq (rep [1], "OK", SEQ_END);
s_recv_seq (req, "OK", SEQ_END); s_recv_seq (req, "OK", SEQ_END);
// Another standard req-rep cycle, just to check // Another standard req-rep cycle, just to check
s_send_seq (req, "E", SEQ_END); s_send_seq (req, "E", SEQ_END);
s_recv_seq (rep [2], "E", SEQ_END); s_recv_seq (rep [2], "E", SEQ_END);