summaryrefslogtreecommitdiff
path: root/src/sub.cpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2012-04-05 07:32:58 +0200
committerMartin Sustrik <sustrik@250bpm.com>2012-04-05 07:32:58 +0200
commitd82cbb3a81f116cd22e9895ecac36ac3d7b38929 (patch)
tree03c923311b937f550bec325d131476513a02bebf /src/sub.cpp
parent52b8a917deb2990e7197b82e81e0258ebe30f424 (diff)
XS_PLUGIN and XS_FILTER implementation
This patch introduces following features: - XS_PLUGIN context option to add plugins to libxs - XS_FILTER option to switch between different filter types - Automatic loading of plug-ins is *not* implemented. From the implementation point of view: - standard prefix filter is implemented as a pluggable filter - trie_t and mtrie_t are joined into a single class - the code for 0MQ/3.1 compatibility is left in in the form of comments - new test for testing re-subscriptions is added Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src/sub.cpp')
-rw-r--r--src/sub.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/sub.cpp b/src/sub.cpp
index 3065345..442dd9b 100644
--- a/src/sub.cpp
+++ b/src/sub.cpp
@@ -21,6 +21,7 @@
#include "sub.hpp"
#include "msg.hpp"
+#include "wire.hpp"
xs::sub_t::sub_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
xsub_t (parent_, tid_, sid_)
@@ -51,14 +52,28 @@ int xs::sub_t::xsetsockopt (int option_, const void *optval_,
// Create the subscription message.
msg_t msg;
+ int rc = msg.init_size (optvallen_ + 4);
+ errno_assert (rc == 0);
+ unsigned char *data = (unsigned char*) msg.data ();
+ if (option_ == XS_SUBSCRIBE)
+ put_uint16 (data, XS_CMD_SUBSCRIBE);
+ else if (option_ == XS_UNSUBSCRIBE)
+ put_uint16 (data, XS_CMD_UNSUBSCRIBE);
+ put_uint16 (data + 2, options.filter_id);
+ memcpy (data + 4, optval_, optvallen_);
+
+#if 0
+ // TODO: This is 0MQ/3.1 protocol.
+ msg_t msg;
int rc = msg.init_size (optvallen_ + 1);
errno_assert (rc == 0);
unsigned char *data = (unsigned char*) msg.data ();
if (option_ == XS_SUBSCRIBE)
- *data = 1;
+ data [0] = 1;
else if (option_ == XS_UNSUBSCRIBE)
- *data = 0;
+ data [0] = 0;
memcpy (data + 1, optval_, optvallen_);
+#endif
// Pass it further on in the stack.
int err = 0;