Problem: issues with nodrop property

- not initialized before use
- name is nasty (boolean variables should not have negative names)

Solution: rename to 'lossy' and initialize to 'true'.
This commit is contained in:
Pieter Hintjens 2014-08-27 12:04:51 +02:00
parent 81485c7688
commit 35040aaf18
2 changed files with 10 additions and 9 deletions

View File

@ -30,6 +30,7 @@ zmq::xpub_t::xpub_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
more (false) more (false)
{ {
options.type = ZMQ_XPUB; options.type = ZMQ_XPUB;
lossy = true;
} }
zmq::xpub_t::~xpub_t () zmq::xpub_t::~xpub_t ()
@ -90,10 +91,6 @@ void zmq::xpub_t::xwrite_activated (pipe_t *pipe_)
int zmq::xpub_t::xsetsockopt (int option_, const void *optval_, int zmq::xpub_t::xsetsockopt (int option_, const void *optval_,
size_t optvallen_) size_t optvallen_)
{ {
if (option_ != ZMQ_XPUB_VERBOSE && option_ != ZMQ_XPUB_NODROP) {
errno = EINVAL;
return -1;
}
if (optvallen_ != sizeof (int) || *static_cast <const int*> (optval_) < 0) { if (optvallen_ != sizeof (int) || *static_cast <const int*> (optval_) < 0) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -101,8 +98,12 @@ int zmq::xpub_t::xsetsockopt (int option_, const void *optval_,
if (option_ == ZMQ_XPUB_VERBOSE) if (option_ == ZMQ_XPUB_VERBOSE)
verbose = (*static_cast <const int*> (optval_) != 0); verbose = (*static_cast <const int*> (optval_) != 0);
else else
nodrop = (*static_cast <const int*> (optval_) != 0); if (option_ == ZMQ_XPUB_NODROP)
lossy = (*static_cast <const int*> (optval_) == 0);
else {
errno = EINVAL;
return -1;
}
return 0; return 0;
} }
@ -131,7 +132,7 @@ int zmq::xpub_t::xsend (msg_t *msg_)
subscriptions.match ((unsigned char*) msg_->data (), msg_->size (), subscriptions.match ((unsigned char*) msg_->data (), msg_->size (),
mark_as_matching, this); mark_as_matching, this);
if (nodrop && !dist.check_hwm ()) { if (lossy == false && !dist.check_hwm ()) {
errno = EAGAIN; errno = EAGAIN;
return -1; return -1;
} }

View File

@ -79,8 +79,8 @@ namespace zmq
// True if we are in the middle of sending a multi-part message. // True if we are in the middle of sending a multi-part message.
bool more; bool more;
// dont drop messages if hwm reached, just return with EAGAIN // Drop messages if HWM reached, otherwise return with EAGAIN
bool nodrop; bool lossy;
// List of pending (un)subscriptions, ie. those that were already // List of pending (un)subscriptions, ie. those that were already
// applied to the trie, but not yet received by the user. // applied to the trie, but not yet received by the user.