From a34ea4d80609395150742259fd8c9caa4409e961 Mon Sep 17 00:00:00 2001 From: Martin Lucina Date: Sun, 20 May 2012 07:40:11 +0200 Subject: Implement SP wire protocol Implements the SP wire protocol, and infrastructure for legacy wire protocol support. Also added an XS_SERVICE_ID socket option to set the service id and renamed the XS_PROTOCOL option to XS_PATTERN_VERSION. The following pattern versions are supported: PAIR: v3 PUBSUB: v1 (legacy), v4 REQREP: v2 PIPELINE: v3 SURVEY: v2 Note that all existing pattern versions have been bumped by 1 to allow for use of legacy protocols (otherwise there would be no way to distinguish between e.g. PUBSUB v3 and PUBSUB v3 using SP). Signed-off-by: Martin Lucina --- src/xrep.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/xrep.cpp') diff --git a/src/xrep.cpp b/src/xrep.cpp index 007ed27..30f1419 100644 --- a/src/xrep.cpp +++ b/src/xrep.cpp @@ -36,6 +36,10 @@ xs::xrep_t::xrep_t (class ctx_t *parent_, uint32_t tid_, int sid_) : next_peer_id (generate_random ()) { options.type = XS_XREP; + options.sp_pattern = SP_REQREP; + options.sp_version = 2; + options.sp_role = SP_REQREP_REP; + options.sp_complement = SP_REQREP_REQ; // TODO: Uncomment the following line when XREP will become true XREP // rather than generic router socket. @@ -55,6 +59,34 @@ xs::xrep_t::~xrep_t () prefetched_msg.close (); } +int xs::xrep_t::xsetsockopt (int option_, const void *optval_, + size_t optvallen_) +{ + if (option_ != XS_PATTERN_VERSION) { + errno = EINVAL; + return -1; + } + + if (optvallen_ != sizeof (int)) { + errno = EINVAL; + return -1; + } + + if (!optval_) { + errno = EFAULT; + return -1; + } + + int version = *(int *) optval_; + if (version != 1) { + errno = EINVAL; + return -1; + } + + options.sp_version = version; + return 0; +} + void xs::xrep_t::xattach_pipe (pipe_t *pipe_, bool icanhasall_) { xs_assert (pipe_); -- cgit v1.2.3