Commit df584a3b authored by Kobolog's avatar Kobolog

an option to fail on unroutable messages in ROUTER sockets

parent 62d27b7a
......@@ -230,6 +230,7 @@ ZMQ_EXPORT int zmq_term (zmq_ctx_t context);
#define ZMQ_SNDTIMEO 28
#define ZMQ_IPV4ONLY 31
#define ZMQ_LAST_ENDPOINT 32
#define ZMQ_FAIL_UNROUTEABLE 33
/* Message options */
#define ZMQ_MORE 1
......
......@@ -33,7 +33,8 @@ zmq::xrep_t::xrep_t (class ctx_t *parent_, uint32_t tid_) :
more_in (false),
current_out (NULL),
more_out (false),
next_peer_id (generate_random ())
next_peer_id (generate_random ()),
fail_unrouteable(false)
{
options.type = ZMQ_XREP;
......@@ -77,6 +78,24 @@ void zmq::xrep_t::xattach_pipe (pipe_t *pipe_, bool icanhasall_)
fq.attach (pipe_);
}
int zmq::xrep_t::xsetsockopt (int option_, const void *optval_,
size_t optvallen_)
{
if (option_ != ZMQ_FAIL_UNROUTABLE) {
errno = EINVAL;
return -1;
}
if(sizeof(optvallen_) != sizeof(uint64_t)) {
errno = EINVAL;
return -1;
}
fail_unroutable = *((const uint64_t*) optval_);
return 0;
}
void zmq::xrep_t::xterminated (pipe_t *pipe_)
{
fq.terminated (pipe_);
......@@ -118,6 +137,8 @@ int zmq::xrep_t::xsend (msg_t *msg_, int flags_)
if (!more_out) {
zmq_assert (!current_out);
int retval = 0;
// If we have malformed message (prefix with no subsequent message)
// then just silently ignore it.
// TODO: The connections should be killed instead.
......@@ -126,7 +147,8 @@ int zmq::xrep_t::xsend (msg_t *msg_, int flags_)
more_out = true;
// Find the pipe associated with the identity stored in the prefix.
// If there's no such pipe just silently ignore the message.
// If there's no such pipe just silently ignore the message, unless
// fail_unreachable is set.
blob_t identity ((unsigned char*) msg_->data (), msg_->size ());
outpipes_t::iterator it = outpipes.find (identity);
......@@ -142,6 +164,9 @@ int zmq::xrep_t::xsend (msg_t *msg_, int flags_)
}
rc = empty.close ();
errno_assert (rc == 0);
} else if(fail_unreachable) {
more_out = false;
retval = EHOSTUNREACH;
}
}
......@@ -150,7 +175,7 @@ int zmq::xrep_t::xsend (msg_t *msg_, int flags_)
errno_assert (rc == 0);
rc = msg_->init ();
errno_assert (rc == 0);
return 0;
return retval;
}
// Check whether this is the last part of the message.
......
......@@ -49,6 +49,7 @@ namespace zmq
// Overloads of functions from socket_base_t.
void xattach_pipe (zmq::pipe_t *pipe_, bool icanhasall_);
int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
int xsend (msg_t *msg_, int flags_);
int xrecv (msg_t *msg_, int flags_);
bool xhas_in ();
......@@ -100,6 +101,9 @@ namespace zmq
// algorithm. This value is the next ID to use (if not used already).
uint32_t next_peer_id;
// If true, fail on unroutable messages instead of silently dropping them.
bool fail_unrouteable;
xrep_t (const xrep_t&);
const xrep_t &operator = (const xrep_t&);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment