summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/options.cpp19
-rw-r--r--src/options.hpp3
-rw-r--r--src/xsub.cpp4
3 files changed, 24 insertions, 2 deletions
diff --git a/src/options.cpp b/src/options.cpp
index 271ebdb..29cf023 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -38,6 +38,7 @@ zmq::options_t::options_t () :
reconnect_ivl_max (0),
backlog (100),
maxmsgsize (-1),
+ filter (1),
immediate_connect (true)
{
}
@@ -172,6 +173,15 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
multicast_hops = *((int*) optval_);
return 0;
+ case ZMQ_FILTER:
+ if (optvallen_ != sizeof (int) || (*((int*) optval_) != 0 &&
+ *((int*) optval_) != 1)) {
+ errno = EINVAL;
+ return -1;
+ }
+ filter = *((int*) optval_);
+ return 0;
+
}
errno = EINVAL;
@@ -317,6 +327,15 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
*optvallen_ = sizeof (int);
return 0;
+ case ZMQ_FILTER:
+ if (*optvallen_ < sizeof (int)) {
+ errno = EINVAL;
+ return -1;
+ }
+ *((int*) optval_) = filter;
+ *optvallen_ = sizeof (int);
+ return 0;
+
}
errno = EINVAL;
diff --git a/src/options.hpp b/src/options.hpp
index fd39a74..e055919 100644
--- a/src/options.hpp
+++ b/src/options.hpp
@@ -75,6 +75,9 @@ namespace zmq
// Maximal size of message to handle.
int64_t maxmsgsize;
+ // If 1, (X)SUB socket should filter the messages. If 0, it should not.
+ int filter;
+
// If true, when connecting, pipes are created immediately without
// waiting for the connection to be established. That way the socket
// is not aware of the peer's identity, however, it is able to send
diff --git a/src/xsub.cpp b/src/xsub.cpp
index a847d7f..60ba598 100644
--- a/src/xsub.cpp
+++ b/src/xsub.cpp
@@ -133,7 +133,7 @@ int zmq::xsub_t::xrecv (msg_t *msg_, int flags_)
// Check whether the message matches at least one subscription.
// Non-initial parts of the message are passed
- if (more || match (msg_)) {
+ if (more || !options.filter || match (msg_)) {
more = msg_->flags () & msg_t::more;
return 0;
}
@@ -173,7 +173,7 @@ bool zmq::xsub_t::xhas_in ()
}
// Check whether the message matches at least one subscription.
- if (match (&message)) {
+ if (!options.filter || match (&message)) {
has_message = true;
return true;
}