diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2010-12-05 09:48:52 +0100 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2010-12-05 09:48:52 +0100 |
commit | 2daa0bb49d52aeb1aa60c94505bdad72348e5d8e (patch) | |
tree | 930b7c24d4c73c0fa8840ee524dd23d047ec12f2 /src/sub.cpp | |
parent | c80e7b80cc726ca7c29493c2553c8d19792bb6e5 (diff) |
XSUB accepts (un)subscriptions in form of messages.
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src/sub.cpp')
-rw-r--r-- | src/sub.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/sub.cpp b/src/sub.cpp index f763558..14f6730 100644 --- a/src/sub.cpp +++ b/src/sub.cpp @@ -17,6 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "../include/zmq.h" + #include "sub.hpp" zmq::sub_t::sub_t (class ctx_t *parent_, uint32_t tid_) : @@ -27,3 +29,32 @@ zmq::sub_t::sub_t (class ctx_t *parent_, uint32_t tid_) : zmq::sub_t::~sub_t () { } + +int zmq::sub_t::xsetsockopt (int option_, const void *optval_, + size_t optvallen_) +{ + if (option_ != ZMQ_SUBSCRIBE && option_ != ZMQ_UNSUBSCRIBE) { + errno = EINVAL; + return -1; + } + + // Create the subscription message. + zmq_msg_t msg; + zmq_msg_init_size (&msg, optvallen_ + 1); + unsigned char *data = (unsigned char*) zmq_msg_data (&msg); + if (option_ == ZMQ_SUBSCRIBE) + *data = 1; + else if (option_ == ZMQ_UNSUBSCRIBE) + *data = 0; + memcpy (data + 1, optval_, optvallen_); + + // Pass it further on in the stack. + int err; + int rc = xsend (&msg, 0); + if (rc != 0) + err = errno; + zmq_msg_close (&msg); + if (rc != 0) + errno = err; + return rc; +} |