mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-13 02:42:58 +01:00
Filtering messages on dish side
This commit is contained in:
parent
c7d52ec260
commit
1960b4e8a9
17
src/dish.cpp
17
src/dish.cpp
@ -97,8 +97,7 @@ int zmq::dish_t::xjoin (const char* group_)
|
||||
return -1;
|
||||
}
|
||||
|
||||
subscriptions_t::iterator it =
|
||||
std::find (subscriptions.begin (), subscriptions.end (), group);
|
||||
subscriptions_t::iterator it = subscriptions.find (group);
|
||||
|
||||
// User cannot join same group twice
|
||||
if (it != subscriptions.end ()) {
|
||||
@ -106,7 +105,7 @@ int zmq::dish_t::xjoin (const char* group_)
|
||||
return -1;
|
||||
}
|
||||
|
||||
subscriptions.push_back (group);
|
||||
subscriptions.insert (group);
|
||||
|
||||
msg_t msg;
|
||||
int rc = msg.init_join ();
|
||||
@ -185,6 +184,8 @@ int zmq::dish_t::xrecv (msg_t *msg_)
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
|
||||
// Get a message using fair queueing algorithm.
|
||||
int rc = fq.recv (msg_);
|
||||
|
||||
@ -193,7 +194,11 @@ int zmq::dish_t::xrecv (msg_t *msg_)
|
||||
if (rc != 0)
|
||||
return -1;
|
||||
|
||||
// Filtering non matching messages
|
||||
subscriptions_t::iterator it = subscriptions.find (std::string(msg_->group ()));
|
||||
if (it != subscriptions.end ())
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool zmq::dish_t::xhas_in ()
|
||||
@ -203,6 +208,7 @@ bool zmq::dish_t::xhas_in ()
|
||||
if (has_message)
|
||||
return true;
|
||||
|
||||
while (true) {
|
||||
// Get a message using fair queueing algorithm.
|
||||
int rc = fq.recv (&message);
|
||||
|
||||
@ -213,8 +219,13 @@ bool zmq::dish_t::xhas_in ()
|
||||
return false;
|
||||
}
|
||||
|
||||
// Filtering non matching messages
|
||||
subscriptions_t::iterator it = subscriptions.find (std::string(message.group ()));
|
||||
if (it != subscriptions.end ()) {
|
||||
has_message = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zmq::blob_t zmq::dish_t::get_credential () const
|
||||
|
@ -81,7 +81,7 @@ namespace zmq
|
||||
dist_t dist;
|
||||
|
||||
// The repository of subscriptions.
|
||||
typedef std::vector<std::string> subscriptions_t;
|
||||
typedef std::set<std::string> subscriptions_t;
|
||||
subscriptions_t subscriptions;
|
||||
|
||||
// If true, 'message' contains a matching message to return on the
|
||||
|
Loading…
Reference in New Issue
Block a user