Fix 1478: receive unsubscriptions in XPUB when verbose

Fixes not receiving unsubscription messages in XPUB socket with
ZMQ_XPUB_VERBOSE and using a XSUB-XPUB proxy in front.

This adds two modifications:

- It adds a new flag, ZMQ_XPUB_VERBOSE_UNSUBSCRIBE, to enable verbose
  unsubscription messages, necessary when using a XSUB/XPUB proxy.

- It adds a boolean switch to zmq::mtrie_t::rm () to control if the
  callback is invoked every time or only in the last removal. Necessary
  when a pipe is terminated and the verbose mode for unsubscriptions is
  enabled.
This commit is contained in:
Ricardo Catalinas Jiménez
2015-07-21 23:35:50 +01:00
parent 305c07583d
commit ec5592db1f
6 changed files with 61 additions and 23 deletions

View File

@@ -159,23 +159,28 @@ bool zmq::mtrie_t::add_helper (unsigned char *prefix_, size_t size_,
void zmq::mtrie_t::rm (pipe_t *pipe_,
void (*func_) (unsigned char *data_, size_t size_, void *arg_),
void *arg_)
void *arg_, bool call_on_uniq_)
{
unsigned char *buff = NULL;
rm_helper (pipe_, &buff, 0, 0, func_, arg_);
rm_helper (pipe_, &buff, 0, 0, func_, arg_, call_on_uniq_);
free (buff);
}
void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
size_t buffsize_, size_t maxbuffsize_,
void (*func_) (unsigned char *data_, size_t size_, void *arg_),
void *arg_)
void *arg_, bool call_on_uniq_)
{
// Remove the subscription from this node.
if (pipes && pipes->erase (pipe_) && pipes->empty ()) {
func_ (*buff_, buffsize_, arg_);
delete pipes;
pipes = 0;
if (pipes && pipes->erase (pipe_)) {
if (!call_on_uniq_ || pipes->empty ()) {
func_ (*buff_, buffsize_, arg_);
}
if (pipes->empty ()) {
delete pipes;
pipes = 0;
}
}
// Adjust the buffer.
@@ -194,7 +199,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
(*buff_) [buffsize_] = min;
buffsize_++;
next.node->rm_helper (pipe_, buff_, buffsize_, maxbuffsize_,
func_, arg_);
func_, arg_, call_on_uniq_);
// Prune the node if it was made redundant by the removal
if (next.node->is_redundant ()) {
@@ -217,7 +222,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
(*buff_) [buffsize_] = min + c;
if (next.table [c]) {
next.table [c]->rm_helper (pipe_, buff_, buffsize_ + 1,
maxbuffsize_, func_, arg_);
maxbuffsize_, func_, arg_, call_on_uniq_);
// Prune redundant nodes from the mtrie
if (next.table [c]->is_redundant ()) {