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/options.cpp | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'src/options.cpp') diff --git a/src/options.cpp b/src/options.cpp index 62c03a2..26fa62c 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -48,7 +48,12 @@ xs::options_t::options_t () : sndtimeo (-1), ipv4only (1), keepalive (0), - protocol (0), + legacy_protocol (false), + sp_service (0), + sp_pattern (-1), + sp_version (-1), + sp_role (-1), + sp_complement (-1), filter (XS_FILTER_PREFIX), survey_timeout (-1), delay_on_close (true), @@ -236,29 +241,29 @@ int xs::options_t::setsockopt (int option_, const void *optval_, return 0; } - case XS_PROTOCOL: + case XS_FILTER: + if (optvallen_ != sizeof (int)) { + errno = EINVAL; + return -1; + } + filter = *((int*) optval_); + return 0; + + case XS_SERVICE_ID: { if (optvallen_ != sizeof (int)) { errno = EINVAL; return -1; } int val = *((int*) optval_); - if (val < 0) { + if (val < 0 || val > 0xffff) { errno = EINVAL; return -1; } - protocol = val; + sp_service = val; return 0; } - case XS_FILTER: - if (optvallen_ != sizeof (int)) { - errno = EINVAL; - return -1; - } - filter = *((int*) optval_); - return 0; - case XS_SURVEY_TIMEOUT: if (type != XS_SURVEYOR) { errno = ENOTSUP; @@ -452,12 +457,21 @@ int xs::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) *optvallen_ = sizeof (int); return 0; - case XS_PROTOCOL: + case XS_PATTERN_VERSION: + if (*optvallen_ < sizeof (int)) { + errno = EINVAL; + return -1; + } + *((int*) optval_) = sp_version; + *optvallen_ = sizeof (int); + return 0; + + case XS_SERVICE_ID: if (*optvallen_ < sizeof (int)) { errno = EINVAL; return -1; } - *((int*) optval_) = protocol; + *((int*) optval_) = sp_service; *optvallen_ = sizeof (int); return 0; -- cgit v1.2.3