Store manual subscriptions in XPUB and send them out on pipe termination.

This commit is contained in:
Fedor Sheremetyev 2016-06-17 11:40:17 +01:00
parent 813c738137
commit baea406683
2 changed files with 22 additions and 4 deletions

View File

@ -92,6 +92,12 @@ void zmq::xpub_t::xread_activated (pipe_t *pipe_)
if (size > 0 && (*data == 0 || *data == 1)) {
if (manual)
{
// Store manual subscription to use on termination
if (*data == 0)
manual_subscriptions.rm(data + 1, size - 1, pipe_);
else
manual_subscriptions.add(data + 1, size - 1, pipe_);
pending_pipes.push_back(pipe_);
pending_data.push_back(blob_t(data, size));
pending_metadata.push_back(sub.metadata());
@ -191,10 +197,19 @@ int zmq::xpub_t::xsetsockopt (int option_, const void *optval_,
void zmq::xpub_t::xpipe_terminated (pipe_t *pipe_)
{
// Remove the pipe from the trie. If there are topics that nobody
// is interested in anymore, send corresponding unsubscriptions
// upstream.
subscriptions.rm (pipe_, send_unsubscription, this, !(verbose_unsubs || manual));
if (manual)
{
// Remove the pipe from the trie and send corresponding manual
// unsubscriptions upstream.
manual_subscriptions.rm (pipe_, send_unsubscription, this, false);
}
else
{
// Remove the pipe from the trie. If there are topics that nobody
// is interested in anymore, send corresponding unsubscriptions
// upstream.
subscriptions.rm (pipe_, send_unsubscription, this, !verbose_unsubs);
}
dist.pipe_terminated (pipe_);
}

View File

@ -79,6 +79,9 @@ namespace zmq
// List of all subscriptions mapped to corresponding pipes.
mtrie_t subscriptions;
// List of manual subscriptions mapped to corresponding pipes.
mtrie_t manual_subscriptions;
// Distributor of messages holding the list of outbound pipes.
dist_t dist;