Add ZMQ_REQ_SEND_RESETS option.

This allows making a new request on a REQ socket by sending a new
message. Without the option set, calling send() after the first message
is done will continue to return an EFSM error.

It's useful for when a REQ is not getting a response. Previously that
meant creating a new socket or switching to DEALER.
This commit is contained in:
Christian Kamm
2013-07-21 13:16:47 +02:00
parent 637f794193
commit a0cc87a9d9
7 changed files with 174 additions and 12 deletions

View File

@@ -30,7 +30,8 @@ zmq::req_t::req_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
message_begins (true),
reply_pipe (NULL),
request_id_frames_enabled (false),
request_id (generate_random())
request_id (generate_random()),
send_resets (false)
{
options.type = ZMQ_REQ;
}
@@ -42,10 +43,17 @@ zmq::req_t::~req_t ()
int zmq::req_t::xsend (msg_t *msg_)
{
// If we've sent a request and we still haven't got the reply,
// we can't send another request.
// we can't send another request unless the send_resets option is enabled.
if (receiving_reply) {
errno = EFSM;
return -1;
if (!send_resets) {
errno = EFSM;
return -1;
}
if (reply_pipe)
reply_pipe->terminate (false);
receiving_reply = false;
message_begins = true;
}
// First part of the request is the request identity.
@@ -197,6 +205,13 @@ int zmq::req_t::xsetsockopt(int option_, const void *optval_, size_t optvallen_)
}
break;
case ZMQ_REQ_SEND_RESETS:
if (is_int && value >= 0) {
send_resets = value;
return 0;
}
break;
default:
break;
}